Opened 14 years ago

Closed 14 years ago

Last modified 12 years ago

#13174 closed (fixed)

readonly_fields in StackedInline forms in the admin are missing the field label.

Reported by: benc Owned by: Gary Wilson
Component: contrib.admin Version: 1.2-beta
Severity: Keywords: admin, forms, inline, label
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

readonly_field in StackedInline forms in the admin are missing the field label.

The field value is shown but the label is missing.

The label of readonly_field in normal forms is ok.

I'm using the example from the docs about inline forms in the admin: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects

  1. in the admin create an Author when readonly_fields is commented out so you can create a book and a title.
  1. remove the comment from readonly_fields from BookInline and see that the Book title exists but the label is missing.
models.py:
class Author(models.Model):
   name = models.CharField(max_length=100)

class Book(models.Model):
   author = models.ForeignKey(Author)
   title = models.CharField(max_length=100)

admin.py:
class BookInline(admin.StackedInline):
    model = Book
    readonly_fields = ('title',)

class AuthorAdmin(admin.ModelAdmin):
    inlines = (BookInline,)

admin.site.register(Author, AuthorAdmin)

Attachments (1)

12843.diff (1003 bytes ) - added by Preston Holmes 14 years ago.

Download all attachments as: .zip

Change History (8)

comment:2 by Russell Keith-Magee, 14 years ago

milestone: 1.2
Triage Stage: UnreviewedAccepted

This is only a problem with StackedInlines; TabularInlines work as expected.

comment:3 by Preston Holmes, 14 years ago

Has patch: set

There were two issues here. First in the init of InlineAdminForm, the model_admin param was not being passed on to the call to the superclass (AdminForm) and so that attribute was getting reset to none. This was screwing up the function at admin.helpers.AdminReadonlyField.label_tag which was expecting model_admin.model to be available.

However even when fixing this, it seems that what is wanted for the label is not something based on the parent model (which is what is found in this context in model_admin.model) but the field name itself, which is available in the local for the label_tag function.

The attached diff fixes these, and in the ad_hoc test as recreated from the report seems to fix things.

by Preston Holmes, 14 years ago

Attachment: 12843.diff added

comment:4 by anonymous, 14 years ago

Owner: changed from nobody to anonymous
Status: newassigned

comment:5 by Gary Wilson, 14 years ago

Owner: changed from anonymous to Gary Wilson
Status: assignednew

comment:6 by Gary Wilson, 14 years ago

Resolution: fixed
Status: newclosed

(In [12857]) Fixed #13174 -- Fixed missing field label for readonly_fields when used in StackedInline, thanks to benc for the report and ptone for the investigation and initial patch.

  • Corrected InlineAdminForm.__init__ to pass along model_admin parameter in super call.
  • Lookup the field label in the form's model, not the model_admin model.

comment:7 by Jacob, 12 years ago

milestone: 1.2

Milestone 1.2 deleted

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