所以,我对 DateTimeField 数据非常了解,我将不胜感激。任务是让用户能够在一天内只创建一个帖子。我有最后一次发帖的日期,现在我应该用今天的日期检查它并获得许可或不获得许可。
我如何检查 datetimefield 数据是今天的日期?
所以让我们看看代码。出了点问题:
class Board (models.Model):
@property
def pub_allowed(self):
try:
last_post_day = self.post_set.all()[self.post_set.count() - 1].created
if last_post_day == utc.localize(datetime.datetime.today()):
return False
return True
except Post.DoesNotExist:
return True
class Post (models.Model):
title = models.CharField (max_length=30)
description = models.CharField (max_length=120)
created = models.DateTimeField (editable=False)
board = models.ForeignKey (Board)
def save(self, *args, **kwargs):
''' On save, update timestamps '''
if not self.id:
self.created = datetime.datetime.today()
return super(Post, self).save(*args, **kwargs)
现在总是返回 True ((