3

I have a queryset like

ses = Session.objects.all() 

that I'd like to get the checksum from (in order to check if there have been changes).
By changes I mean created/deleted/updated rows.

I imagined:

from django.core import serializers new_chksum = serializers.serialize("json", ses).__hash__() 

Is it a good way to know if there have been changes in the queryset ?

4
  • Have a look at this question: stackoverflow.com/questions/5240670/… Commented Jul 26, 2012 at 9:18
  • The OP is asking about a row wise check. I'm looking for an entire queryset check (maybe created/deleted/changed rows) Commented Jul 26, 2012 at 10:00
  • If you use a dirty_bit field you can easily see if the queryset has changed by filtering it: QS.objects.filter(dirty_bit=True). Not only will it tell you if the QS is changed, but it will tell you which rows have changed too Commented Jul 26, 2012 at 10:11
  • It won't tell me if there are deleted rows, and created ones will not be dirty, isn't it ? Commented Jul 26, 2012 at 10:32

1 Answer 1

1

So this problem may be very complex --- if you want just to know whether any row in a particular table was touched (like: has any session changed from last time I checked). You could for example store some version id in another table, this value would be incremented every time instance of Session model is changed.

To do the incrementation you might need to use database triggers and sequence.

Sign up to request clarification or add additional context in comments.

2 Comments

My original idea is to provide a calendar which polls (with ajax) for changes and updates itself if any. So I think I could give a hash to the client for each new version of the schedule to be compared when polling.
Well, this could kill your database. Because for every poll you'll execute query that takes all calendar events, serialize it and then hash it. Depending on size of the resulset overhead might be too big.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.