Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 952
codyc4321 Avatar asked Jan 03 '23 08:01

codyc4321


1 Answers

You need to keep it in readonly_fields

class EventAdmin(admin.ModelAdmin):
    fields = ['product_type',]
    readonly_fields=('received_time',)
like image 116
Sandeep Balagopal Avatar answered Jan 05 '23 22:01

Sandeep Balagopal