如何在django管理页面中填充datefield?

时间:2015-06-09 02:47:15

标签: python django

尝试以下方法:

from datetime import datetime
class ArticleAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title',), 'pub_date':(datetime.now()) }

提出了什么:

错误:

<class 'news.admin.ArticleAdmin'>: (admin.E028) The value of 'prepopulated_fields' refers to 'pub_date', which must not be a DateTimeField, ForeignKey or ManyToManyField.
<class 'news.admin.ArticleAdmin'>: (admin.E029) The value of 'prepopulated_fields["pub_date"]' must be a list or tuple.

2 个答案:

答案 0 :(得分:1)

你忘记了元组的逗号。

O(1)

答案 1 :(得分:0)

  

prepopulated_fields不接受DateTimeField,ForeignKey和ManyToManyField字段。

来自docs