#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
- in the admin create an Author when readonly_fields is commented out so you can create a book and a title.
- 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)
Change History (8)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
milestone: | → 1.2 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 15 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 , 15 years ago
Attachment: | 12843.diff added |
---|
comment:4 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:6 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(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 alongmodel_admin
parameter insuper
call. - Lookup the field label in the form's model, not the
model_admin
model.
This is only a problem with StackedInlines; TabularInlines work as expected.