我意识到当我运行updateview时,listdate更改为我更新列表的时间。这是我的模型。py
类列表(models.Model):
list_date = models.DateTimeField('date created', blank=True, auto_now=True)
favourite = models.ManyToManyField(User, related_name="favourite", blank=True)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse("user-dashboard")
def save(self, *args, **kwargs):
if self.is_published and self.list_date is None:
self.list_date = datetime.datetime.now()
elif not self.is_published and self.list_date is not None:
self.list_date = None
super(Listing, self).save(*args, **kwargs)
答案 0 :(得分:0)
您需要将auto_now
更改为auto_now_add
。
list_date = models.DateTimeField('date created', blank=True, auto_now_add=True)