首页 > django的model写法

django的model写法

一个很小白的问题,麻烦大家帮忙看看。

一个教程里有这么一段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)


create_date = models.DateTimeField(auto_now_add=True, editable=True, verbose_name='发布时间')
    publish_date = models.DateTimeField(auto_now=True, null=True, verbose_name='更新时间')
    
    这样是可以的 我就是这样设计的 在后台修改完文章后就能看到时间的变化了
【热门文章】
【热门文章】