一个很小白的问题,麻烦大家帮忙看看。
一个教程里有这么一段model:
class Post(models.Model):
author = models.ForeignKey(User)
title = models.CharField(max_length=200)
text = models.TextField()
create_date = models.DateTimeField(default=timezone.now)
publish_date = models.DateTimeField(blank=True, null=True)
1、我始终在后台看不到published_date字段。我print的话显示如下:
post = Post.objects.get(id=1)
post.create_date
datetime.datetime(2015, 9, 18, 7, 38, 37, tzinfo=<UTC>)
post.publish_date
<bound method Post.publish_date of <Post: one more time>>
2、create_date是创建时间默认当前时间,publish_date是最后提交的时间。在model里没有看到任何体现这两个时间的差别的,到底怎么写能让这两个数据一个是创建的时间,一个是最后更新的时间呢。
python纯新手,谢谢大家的帮助!
试试这个:
create_date = models.DateTimeField(auto_now_add=True,auto_now=False)
publish_date = models.DateTimeField(auto_now_add=False,auto_now=True)