Every time there's an INSERT/UPDATE of this model I want to check that the 'personprofile' hasn't been committed to more a days work on that date ?
By 'committed' I mean I only want the update to continue if, after it's finished, the total of proportion_of_day_required
on all instances of PersonRequirement
with the same personprofile
and the same date
is 1.0 or less.
class PersonRequirement(models.Model):
'''
Joins a person to a Subproject on a given
day and nominates how much of that day
they are required for
'''
subproject = models.ForeignKey(SubProject, on_delete=models.CASCADE)
personprofile = models.ForeignKey(PersonProfile, on_delete=models.CASCADE)
date = models.DateField()
proportion_of_day_required = models.DecimalField(max_digits=3, decimal_places=2)
I was looking at the save method on the model but I wasn't sure whether trying to read other instances of the same model would be OK while trying to insert/update an instance of the same model ?
Maybe there's a better way which I've overlooked ?