Search code examples
pythondjangodjango-querysetchecksum

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 ?


Solution

  • 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.