I have a django model which contains details of when a particular task (email reminder) should be run for a particular booking.
It looks a bit like this:-
class Task(models.Model):
PENDING = 'pending'
IN_PROGRESS = 'in_progress'
COMPLETE = 'complete'
STATES = (
(PENDING, 'Pending'),
(IN_PROGRESS, 'In Progress'),
(COMPLETE, 'Complete')
)
run_at = models.DateTimeField()
state = models.CharField(max_length=50, choices=STATES, default=PENDING)
class Meta:
ordering = ['run_at']
When the date of the booking is changed, I want the corresponding task's run_at time to be updated.
As far as I can see, there are a few ways I can do this:-
- In the view code.
- In the save method of the Task model.
- Using signals.
In general, I think it makes most sense to use the view code - it's more explicit that way. But the code I'm working with is very old and the date of bookings can be changed from all sorts of places in all sorts of ways and I'm not convinced I can be 100% certain that I've caught every single place in which this can happen. If I miss any, the Task won't be updated in that case.
Plus, if anyone else adds code that changes booking dates, they'll have to know to update the tasks.
So would it make more sense to use the save method? Or just try and be as thorough as I can and find all the places that the booking date could be altered?