尝试了以下操作:
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.发布于 2015-06-09 11:07:06
您忘记了元组的逗号。
from datetime import datetime
class ArticleAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug': ('title',), 'pub_date': (datetime.now(), ) }发布于 2015-06-10 14:10:15
prepopulated_fields不接受DateTimeField、ForeignKey或ManyToManyField字段。
来自docs的。
https://stackoverflow.com/questions/30722215
复制相似问题