2👍
✅
You can override the save()
method to do something like this, so that every time you change your job model it recalculates pending. Although I agree with limelights that the pending()
method isn’t bad either.
class Job(models.Model):
accepted = ...
reject = ...
pending = ... (Boolean Fields)
def save(self, *args, **kwargs):
self.pending = (not self.accepted) and (not self.rejected)
super(Job, self).save(*args, **kwargs) # Call the "real" save() method.
https://docs.djangoproject.com/en/dev/topics/db/models/#overriding-predefined-model-methods
Source:stackexchange.com