[Django] #29184: TabularInline Read-only Fields Ignore ModelForm._meta Label and Help Text Overrides

10 views
Skip to first unread message

Django

unread,
Mar 4, 2018, 7:46:27 AM3/4/18
to django-...@googlegroups.com
#29184: TabularInline Read-only Fields Ignore ModelForm._meta Label and Help Text
Overrides
-------------------------------------+-------------------------------------
Reporter: David | Owner: nobody
Sanders |
Type: Bug | Status: new
Component: | Version: 2.0
contrib.admin | Keywords: readonly,
Severity: Normal | help_texts, labels
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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
[https://github.com/django/django/blob/a38ae914d89809aed6d79337b74a8b31b6d3849a/django/contrib/admin/helpers.py#L264
code which provides them] never looks at `ModelForm._meta`, but
[https://github.com/django/django/blob/a38ae914d89809aed6d79337b74a8b31b6d3849a/django/contrib/admin/helpers.py#L167
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`.

--
Ticket URL: <https://code.djangoproject.com/ticket/29184>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 4, 2018, 7:46:44 AM3/4/18
to django-...@googlegroups.com
#29184: TabularInline Read-only Fields Ignore ModelForm._meta Label and Help Text
Overrides
-------------------------------------+-------------------------------------
Reporter: David Sanders | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:
Keywords: readonly, | Triage Stage:
help_texts, labels | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Sanders):

* Attachment "tabularinline_label_and_help_text.patch" added.

Django

unread,
Mar 5, 2018, 1:04:21 PM3/5/18
to django-...@googlegroups.com
#29184: TabularInline read-only fields ignore ModelForm Meta.labels and help_texts

-------------------------------------+-------------------------------------
Reporter: David Sanders | Owner: nobody
Type: Bug | Status: new

Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:
Keywords: readonly, | Triage Stage: Accepted
help_texts, labels |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted
* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/29184#comment:1>

Django

unread,
Mar 6, 2018, 1:17:52 AM3/6/18
to django-...@googlegroups.com
#29184: TabularInline read-only fields ignore ModelForm Meta.labels and help_texts
-------------------------------------+-------------------------------------
Reporter: David Sanders | Owner: nobody
Type: Bug | Status: new

Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:
Keywords: readonly, | Triage Stage: Accepted
help_texts, labels |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Sanders):

* Attachment "tabularinline_label_and_help_text_2.patch" added.

Fixed patch

Django

unread,
Mar 6, 2018, 1:18:45 AM3/6/18
to django-...@googlegroups.com
#29184: TabularInline read-only fields ignore ModelForm Meta.labels and help_texts
-------------------------------------+-------------------------------------
Reporter: David Sanders | Owner: nobody
Type: Bug | Status: new

Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:
Keywords: readonly, | Triage Stage: Accepted
help_texts, labels |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by David Sanders):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/29184#comment:2>

Django

unread,
Mar 7, 2018, 3:53:09 PM3/7/18
to django-...@googlegroups.com
#29184: TabularInline read-only fields ignore ModelForm Meta.labels and help_texts
-------------------------------------+-------------------------------------
Reporter: David Sanders | Owner: Danil
| Kozyatnikov
Type: Bug | Status: assigned

Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:
Keywords: readonly, | Triage Stage: Accepted
help_texts, labels |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Danil Kozyatnikov):

* owner: nobody => Danil Kozyatnikov
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/29184#comment:3>

Django

unread,
Mar 13, 2018, 12:30:32 PM3/13/18
to django-...@googlegroups.com
#29184: TabularInline read-only fields ignore ModelForm Meta.labels and help_texts
-------------------------------------+-------------------------------------
Reporter: David Sanders | Owner: Danil
| Kozyatnikov
Type: Bug | Status: assigned
Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:
Keywords: readonly, | Triage Stage: Accepted
help_texts, labels |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_tests: 1 => 0


Comment:

[https://github.com/django/django/pull/9767 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/29184#comment:4>

Django

unread,
Mar 15, 2018, 5:03:29 AM3/15/18
to django-...@googlegroups.com
#29184: TabularInline read-only fields ignore ModelForm Meta.labels and help_texts
-------------------------------------+-------------------------------------
Reporter: David Sanders | Owner: Danil
| Kozyatnikov
Type: Bug | Status: assigned
Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:
Keywords: readonly, | Triage Stage: Accepted
help_texts, labels |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* needs_better_patch: 0 => 1


Comment:

Overall patch in PR looks good.

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

Thanks Danil.

--
Ticket URL: <https://code.djangoproject.com/ticket/29184#comment:5>

Django

unread,
Mar 17, 2018, 9:14:44 PM3/17/18
to django-...@googlegroups.com
#29184: TabularInline read-only fields ignore ModelForm Meta.labels and help_texts
-------------------------------------+-------------------------------------
Reporter: David Sanders | Owner: Danil
| Kozyatnikov
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution: fixed

Keywords: readonly, | Triage Stage: Accepted
help_texts, labels |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"274e3e27f366bddbf1bb13b40c3c7b95195c496e" 274e3e2]:
{{{
#!CommitTicketReference repository=""
revision="274e3e27f366bddbf1bb13b40c3c7b95195c496e"
Fixed #29184 -- Made TabularInline respect model form's Meta.labels and
help_texts.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29184#comment:6>

Reply all
Reply to author
Forward
0 new messages