Opened 16 years ago

Closed 16 years ago

Last modified 10 years ago

#7993 closed Uncategorized (invalid)

Admin complains about a missing field even if it is not missing

Reported by: Ivan Giuliani Owned by: nobody
Component: contrib.admin Version: dev
Severity: Normal Keywords: admin, improperlyconfigured
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Django raises an ImproperlyConfigured exception (NewsAdmin.fieldsets[1][1]['fields'] refers to field `pub_date` that is missing from the form) when the following admin interface is defined:

class NewsAdmin(admin.ModelAdmin):
    fieldsets = (
        (None, {
            'fields': ('title', 'text'),
        (_('Other stuff'), {
            'fields': ('language', 'pub_date'),

But the model has a pub_date field:

class News(models.Model):
    title = models.CharField(max_length=50)
    pub_date = models.DateTimeField(auto_now=True, blank=True)
    text = models.TextField()
    language = models.ForeignKey(LanguageRef)

    def save(self):
        if not self.pub_date:
            self.pub_date =
        super(News, self).save()

    class Meta:
        get_latest_by = "pub_date"
        verbose_name = "news"
        verbose_name_plural = "news"

If I remove pub_date from the fields attribute in the NewsAdmin everything works as expected.

Change History (6)

comment:1 by Karen Tracey, 16 years ago

Resolution: invalid
Status: newclosed

I suspect you get the error because auto_now=True is specified for this field. That makes it a non-editable field, since the value is not something the user can change, see

"Note that the current date is always used; it’s not just a default value that you can override."

Since it's not editable there's no point in putting it in the form.

comment:2 by Batiste Bieler, 14 years ago

That would be still useful to be able to display the field in the admin. Maybe in a disabled input, ie: <input disabled />

in reply to:  2 comment:3 by Karen Tracey, 14 years ago

Replying to batiste:

That would be still useful to be able to display the field in the admin. Maybe in a disabled input, ie: <input disabled />

This is possible now (new in 1.2) with readonly fields in the admin, though it does not actually used disabled inputs.

comment:4 by anonymous, 12 years ago

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

For others who may run into this symptom for unrelated reasons, try restarting your server.

comment:5 by mwaigaryan@…, 11 years ago

same problem in Django-1.4.2,is there a patch?

in reply to:  5 comment:6 by alextreppass@…, 10 years ago

Replying to mwaigaryan@…:

same problem in Django-1.4.2,is there a patch?

As above, put it in the readonly_fields list in the model admin, then it displays fine

Note: See TracTickets for help on using tickets.
Back to Top