开发者

Django - Update model data before access?

开发者 https://www.devze.com 2022-12-18 06:30 出处:网络
Any pointers on how I can update the data for a model on each access? If I have code that accesses a Person 开发者_运维技巧object like so:

Any pointers on how I can update the data for a model on each access?

If I have code that accesses a Person 开发者_运维技巧object like so: p = Person.objects.get(username='darkpixel')

I would like to fire off my own process to check an external site and possibly update the Person model before returning it.

I'm hesitant to override the get method. Is there a better way?


That code definitely belongs in your Manager. I wouldn't override get, but I would create a function named get_and_resync to do the job for you.


Turn the fields on the model into properties.

0

精彩评论

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