Reputation: 11
Below is my codes
class Job(models.Model):
pin_till = models.DateTimeField("Pin Job Post", null=True,blank=True)
Here i wanna auto setup pin_till_date field to None if date is not None and than pin_till_date < now(). Depend on current time and auto check this field to None.
How to archives this method ah? with @property function, signals or just define in save function?
Upvotes: 1
Views: 83
Reputation: 1588
You can Override Save()
class Job(models.Model):
def save(self, *args, **kwargs):
if self.pin_till < now(): # Or what ever be the condition
# Use your conditon and update
self.pin_till = None
super(Job, self).save(*args, **kwargs) #Save the modified value
Upvotes: 1