JoeManFoo
JoeManFoo

Reputation: 359

Django Admin error out that a field that is missing from the form

Getting an error with my admin.py file: 'BaseAdmin.fieldsets[1][1]['fields']' refers to field 'publish_on' that is missing from the form.

my class looks like:

class Base(models.Model):
    ...
    publish_on = models.DateTimeField(auto_now=True, db_index=True)
    ...

My admin.py looks like:

class BaseAdmin(admin.ModelAdmin):
    ...
    fieldsets = [
        ('Dates', {
            'fields': ('publish_on',)
        }),
    ]

if I change out my admin class with 'pass' or just register with the model class then the date time field shows up.

Upvotes: 3

Views: 4159

Answers (2)

bjw
bjw

Reputation: 2017

If you do want to use auto_now_add, but then leave open the possibility of changing the date, you could use default=datetime.now in the model field. This sets a default in the admin, but lets the user change it, and it works in inlines.

Upvotes: 4

rombarcz
rombarcz

Reputation: 1614

This error is caused by auto_now and also by auto_now_add. To remedy that add

readonly_fields = ("publish_on",)

in your BaseAdmin (only in django 1.2 and newer).

Upvotes: 6

Related Questions