开发者

Implementing a per-model table modification time in Django?

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开发者_Go百科 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜