Opened 15 years ago

Last modified 13 years ago

#12481 closed

admin readonly_fields not working with edtiable=False field named in fieldset — at Version 8

Reported by: Tim Miller Owned by: nobody
Component: contrib.admin Version: 1.2-beta
Severity: Keywords:
Cc: Jannis Leidel Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Russell Keith-Magee)

If a field is marked editable=False, and it is included in a fieldset in a model admin, and it is also listed in readonly_fields, an error is raised:

'PostAdmin.fieldsets[1][1]['fields']' refers to field 'date_modified' that is missing from the form.

Change History (10)

comment:1 by Karen Tracey, 15 years ago

Resolution: worksforme
Status: newclosed

I can't recreate any problem along the lines you sketch out. I just added readonly_fields to one of my ModelAdmin classes that has fieldsets specified, listing several of the fields specified in fieldsets, and it works fine. They display and are not editable; no error. r12063 if it matters.

comment:2 by Tim Miller, 15 years ago

It looks like I was misusing readonly_fields then. I was using it to display fields that were set editable=False rather than using it on normal fields.

    date_created = models.DateField(auto_now_add=True, verbose_name='created')

That model field or any normal one to which I add editable=False will normally not display in an admin add or change form but if I list it in readonly_fields it does display. It also lets me position it with fields but not with fieldsets.

comment:3 by Alex Gaynor, 15 years ago

Using readonly_fields with editable=False should be supported. (I bet it actually works but the validation fails on it).

comment:4 by Tim Miller, 15 years ago

Resolution: worksforme
Status: closedreopened

I'm reopening the ticket, Alex is right in that it does actually display in admin when I comment out the relevant validation.

contrib/admin/validation.py

def check_formfield(cls, model, opts, label, field):
    if getattr(cls.form, 'base_fields', None):
        try:
            cls.form.base_fields[field]
        except KeyError:
            raise ImproperlyConfigured("'%s.%s' refers to field '%s' that "
                "is missing from the form." % (cls.__name__, label, field))
    else:
        fields = fields_for_model(model)
        try:
            fields[field]
        except KeyError:
            print "hit check_formfield keyerror #2"
            #raise ImproperlyConfigured("'%s.%s' refers to field '%s' that "
            #    "is missing from the form." % (cls.__name__, label, field))

comment:5 by Jannis Leidel, 15 years ago

Cc: Jannis Leidel added

by Tim Miller, 15 years ago

Attachment: rofv1.diff added

comment:6 by Tim Miller, 15 years ago

Has patch: set

comment:7 by Tim Miller, 15 years ago

Related problem with readonly_fields, I'm still trying to work out if it's the app or django yet. Using django-reversion to rollback to a previous model state fails with:

Caught an exception while rendering: Key 'date_created' not found in Form

traceback: http://dpaste.com/hold/140812/

comment:8 by Russell Keith-Magee, 15 years ago

Description: modified (diff)
milestone: 1.2
Summary: admin readonly_fields not working with fieldsetsadmin readonly_fields not working with edtiable=False field named in fieldset
Triage Stage: UnreviewedAccepted
Version: SVN1.2-beta

Updated ticket title and description to reflect the actual problem

by Alex Gaynor, 15 years ago

Tests + fix.

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