I have a Django application which edits a database table, which another application polls and uses to update a downstream system. In order to minimize processing when the database has not been altered in between polls, I would like to use a global modification time for a model, which is updated every time a row is created/deleted/modified. How can I do this within the Django ORM?
+2
A:
Django does not give you access, nor does it maintain, a "last modified" date on a table (model). You need to implement this by yourself, but this isn't complicated.
The easiest way would be to catch the necessary signals in your model by implementing the post_save()
and post_delete()
model signals (hooks, basically), and maintaining a static date field which represents the "last modified" date you are looking for.
Yuval A
2010-08-02 21:46:40
Thanks -- could you possibly expand on the concept of a "static field": is this a separate Model?
kdt
2010-08-03 09:40:01
Well, you could do a separate model, but that's unnecessary. I would stick it in the models `Meta` class.
Yuval A
2010-08-03 10:23:01