Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#22087 closed Bug (fixed)

ModelForm Meta overrides are ignored by AdminReadonlyField

Reported by: Ben Davis Owned by: nobody
Component: contrib.admin Version: master
Severity: Normal Keywords:
Cc: Ben Davis Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


In some cases, we may want to override the label and/or help text for admin fields. This can be done on the ModelForm's Meta class, or by passing the overrides to ModelAdmin.get_form. See documentation: Overriding the default fields

When a field is readonly, the AdminReadonlyField class ignores the form overrides. Ideally the AdminReadonlyField should check first for the overrides on form._meta, and fallback to the label_for_field() and help_text_for_field() functions.

Change History (7)

comment:1 Changed 4 years ago by Ben Davis

Cc: Ben Davis added

comment:2 Changed 4 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

I think the ideal solution would be to get rid of custom logic in AdminReadonlyField as much as possible, adding functionality to django.forms as necessary.

comment:3 Changed 4 years ago by Ben Davis

Has patch: set

Hmm, I'm not sure how you could avoid custom logic in the AdminReadonlyField for this. This bug is only relevant to the admin, which already creates wrappers around every field. The bug is in the wrapper itself, not with the forms.

At any rate, I've created a pull request for a fix, with tests. Let me know what you think.

comment:4 Changed 3 years ago by anonymous

Has there been any update on this?


comment:5 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 16afffffe87bf8b7de6403329937433ac5096697:

Fixed #22087 -- Made AdminReadonlyField respect ModelForm Meta overrides.

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

In 24604844866a0b28122a1c47ac85072ea05b9b71:

[1.7.x] Fixed #22087 -- Made AdminReadonlyField respect ModelForm Meta overrides.

Backport of 16afffffe8 from master

comment:7 Changed 3 years ago by Tim Graham

We could backport the fix to 1.6.x as it's a bug in a new feature, but I haven't done so because there were several conflicts. Feel free to send a PR for that along with a note in the 1.6.3 release notes if you'd like.

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