Re: Looking for a way to detect changes in database records with low storage footprint
You could grab the __dict__ of the instance and use that.
import hashlib
hash = hashlib.md5()
hash.update(str(MyModel.objects.get(pk = 1).__dict__))
hash.digest()
On Thursday, October 10, 2013 8:55:27 AM UTC-5, DJ-Tom wrote:
-- import hashlib
hash = hashlib.md5()
hash.update(str(MyModel.objects.get(pk = 1).__dict__))
hash.digest()
On Thursday, October 10, 2013 8:55:27 AM UTC-5, DJ-Tom wrote:
Thanks, but *how* can I create a hash from a database object in Django - is there a generic method to iterate over all (or only specific) fields and get a hash value?
Am Mittwoch, 9. Oktober 2013 19:07:54 UTC+2 schrieb Nikolas Stevenson-Molnar:A hash should work fine. Alternatively, you could diff the two records,
using something like difflib: http://docs.python.org/2/library/difflib.html
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/77cbde22-923a-49ff-8d6e-ee91db6adbe3%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home