Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - QuerySet checksum

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 ?

like image 859
Pierre de LESPINAY Avatar asked Nov 19 '25 23:11

Pierre de LESPINAY


1 Answers

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.

like image 90
jb. Avatar answered Nov 21 '25 12:11

jb.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!