codyc4321
codyc4321

Reputation: 9682

FieldError: Unknown field(s) (received_time) specified for Event. Check fields/fieldsets/exclude attributes of class EventAdmin

I have the following model

class Event(models.Model):
    product_type = models.CharField(max_length=250, null=False, blank=False)
    received_time = models.DateTimeField(editable=False)

in admin:

class EventAdmin(admin.ModelAdmin):
    fields = ['product_type', 'received_time']

I get the following error when trying to edit an event (clicking on an individual event in the admin):

FieldError at /admin/events/event/20/
Unknown field(s) (received_time) specified for Event. Check fields/fieldsets/exclude attributes of class EventAdmin.

I do see that editable=False but I still want it to at least be visible, even it it isn't editable. Is there a way to fix this error and edit these items in admin?

Upvotes: 4

Views: 5144

Answers (1)

Sandeep Balagopal
Sandeep Balagopal

Reputation: 1983

You need to keep it in readonly_fields

class EventAdmin(admin.ModelAdmin):
    fields = ['product_type',]
    readonly_fields=('received_time',)

Upvotes: 12

Related Questions