Opened 8 years ago
Closed 8 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)
Change History (8)
by , 8 years ago
| Attachment: | tabularinline_label_and_help_text.patch added |
|---|
comment:1 by , 8 years ago
| Needs tests: | set |
|---|---|
| Summary: | TabularInline Read-only Fields Ignore ModelForm._meta Label and Help Text Overrides → TabularInline read-only fields ignore ModelForm Meta.labels and help_texts |
| Triage Stage: | Unreviewed → Accepted |
by , 8 years ago
| Attachment: | tabularinline_label_and_help_text_2.patch added |
|---|
comment:2 by , 8 years ago
Tweaked the patch a little bit to fix a situation it broke with pure form fields (no model field).
comment:3 by , 8 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:5 by , 8 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.
Fixed patch