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
一旦我在MessMenu中創建對象,我希望django在7天后刪除該對象。請讓我知道如何在給定的時間段後刪除某個對象。如何刪除特定日期後django中的某個模型實例
你需要寫檢查的是7天前的代碼,然後刪除它們......然後你需要一種方法來調用代碼。 – Sayse
你能否詳述@Sayse – yogs