'How to update django model automatically on due date?

I am trying to create a task manager app in Django. Tasks have a due date and is_complete status.

class Task(models.Model):
  title = models.CharField(max_length=30)
  description = models.CharField(max_length=30)
  expire_date = models.DateField()
  is_completed =  models.BooleanField(default=False)

At the time of the task creation, the users should choose the automatically rescheduling option for certain days in case the task is either completed or expired. How can I automatically reschedule the task for the number of days the user has chosen?



Solution 1:[1]

Do you think this could be done with a custom django admin command, that gets called through a cron job every day/night? I implemented a similar system that way:

  • create one management command (for example, reschedule_expired_tasks)
  • create a cron job in linux/your server like 0 0 * * * python /var/www/myapp/manage.py reschedule_expired_tasks

That way you can check with the command which tasks are expiring today, and just change their new due date to the number of days a user has specified somewhere.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1