簡體   English   中英

有沒有辦法讓updateview中的時間與django中createview中的時間保持一致

[英]is there a way to keep the time in updateview same as the time in createview in django

我意識到當我運行 updateview 時,listdate 更改為我更新列表的時間。這是我的 models.py

類列表(模型。模型):

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM