python - How to delete a certain model instance in django after a given date -
class mess(models.model): muser = models.onetoonefield(user) mess_name = (('gh','girls hostel top mess'), ('ih','girls hostel down mess'), ('mm','mega mess'), ('fb','first block mess'), ('sb','second block mess'), ('tb','third block mess'), ) mess_name = models.charfield(max_length=25, choices =mess_name,primary_key=true) per_day_cost = models.integerfield() def __str__(self): return self.mess_name class messmenu(models.model): mess_name = models.foreignkey(mess) day = models.datefield() morning = models.textfield() afternoon = models.textfield() snacks = models.textfield() dinner = models.textfield() def __str__(self): return self.mess_name
once create object in messmenu want django delete object after 7 days. please let me know how delete object after given period of time.
add creation_date model.
if model belongs user: check if models outdated when user logs in.
otherwise write method call before access model. returns true if can access model , false, if it's outdated. if returns false delete it.
or write watchdog.
Comments
Post a Comment