我有以下型号
class Event(models.Model):
product_type = models.CharField(max_length=250, null=False, blank=False)
received_time = models.DateTimeField(editable=False)
在admin:
class EventAdmin(admin.ModelAdmin):
fields = ['product_type', 'received_time']
我在尝试编辑活动时遇到以下错误(点击管理员中的单个活动):
FieldError at /admin/events/event/20/
Unknown field(s) (received_time) specified for Event. Check fields/fieldsets/exclude attributes of class EventAdmin.
我确实看到editable=False
,但我仍然希望它至少是可见,即使它不可编辑。有没有办法修复此错误并在管理员中编辑这些项目?
答案 0 :(得分:3)
您需要将其保存在readonly_fields
中class EventAdmin(admin.ModelAdmin):
fields = ['product_type',]
readonly_fields=('received_time',)