Opened 6 years ago

Closed 6 years ago

#29184 closed Bug (fixed)

TabularInline read-only fields ignore ModelForm Meta.labels and help_texts

Reported by: David Sanders Owned by: Danil Kozyatnikov
Component: contrib.admin Version: 2.0
Severity: Normal Keywords: readonly, help_texts, labels
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Providing a ModelForm for admin.TabularInline will have any Meta.labels or Meta.help_texts overrides for read-only fields ignored. This behavior is inconsistent with ModelAdmin and admin.StackedInline, which *do* respect those overrides.

The difference in behavior comes down to the template rendering: with TabularInline the field names are rendered separately from the values, and so the label and help text are accessed differently. The code which provides them never looks at ModelForm._meta, but code further up in the same file does.

I'm attaching a crude patch against master which factors out the existing logic and reuses it in both spots I linked. Discovered this issue while trying to meet a deadline for a project so I don't have time to do a proper PR or even run the tests. The patch works for my manual testing, but your mileage may vary. It at least illustrates where the issue is and a possible fix. Note: The patch does not keep the behavior in AdminReadonlyField where it flips between using class_name and field. No explanation is given in the code for why it alternates, and it seems illogical to me, but maybe someone knows better. The patch simply uses class_name.

Attachments (2)

tabularinline_label_and_help_text.patch (3.2 KB ) - added by David Sanders 6 years ago.
tabularinline_label_and_help_text_2.patch (3.3 KB ) - added by David Sanders 6 years ago.
Fixed patch

Download all attachments as: .zip

Change History (8)

by David Sanders, 6 years ago

comment:1 by Tim Graham, 6 years ago

Needs tests: set
Summary: TabularInline Read-only Fields Ignore ModelForm._meta Label and Help Text OverridesTabularInline read-only fields ignore ModelForm Meta.labels and help_texts
Triage Stage: UnreviewedAccepted

by David Sanders, 6 years ago

Fixed patch

comment:2 by David Sanders, 6 years ago

Tweaked the patch a little bit to fix a situation it broke with pure form fields (no model field).

comment:3 by Danil Kozyatnikov, 6 years ago

Owner: changed from nobody to Danil Kozyatnikov
Status: newassigned

comment:4 by Tim Graham, 6 years ago

Needs tests: unset

comment:5 by Carlton Gibson, 6 years ago

Patch needs improvement: set

Overall patch in PR looks good.

Just a few adjustments needed (comments on PR). Please uncheck Patch needs improvement when these are addressed.

Last edited 6 years ago by Carlton Gibson (previous) (diff)

comment:6 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 274e3e2:

Fixed #29184 -- Made TabularInline respect model form's Meta.labels and help_texts.

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