Update model field after a certain period

27 views
Skip to first unread message

salma.ess...@gmail.com

unread,
Jan 6, 2016, 8:07:30 AM1/6/16
to Django users
I have a Django model with a Boolean field called New. During the model creation it's set to True, but I want it to be updated automatically to False after a certain period (1 month post creation for example). Can I use signals here?

Mark Harley

unread,
Jan 6, 2016, 9:30:27 AM1/6/16
to Django users
One option would be to create a custom management command (https://docs.djangoproject.com/en/1.9/howto/custom-management-commands/) that checks for models with a `created_at < now - 1month`. You could then run this, say once a day, using crontab (https://help.ubuntu.com/community/CronHowto). Here created_at is a `datetime` field with `auto_now_add=True`.

Tom Evans

unread,
Jan 6, 2016, 9:37:21 AM1/6/16
to django...@googlegroups.com
Another option is to replace the field with a "created" date time, and
add a computed property called "new" that tests to see whether it is
old or not.

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages