i have realised that when i run the updateview the listdate changes to the time I updated the listing.Here is my models.py
class Listing(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)
您需要将auto_now
更改为auto_now_add
。
list_date = models.DateTimeField('date created', blank=True, auto_now_add=True)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.