Opened 13 months ago

Closed 11 months ago

Last modified 11 months ago

#22087 closed Bug (fixed)

ModelForm Meta overrides are ignored by AdminReadonlyField

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

Description

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 13 months ago by bendavis78

  • Cc bendavis78 added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 13 months ago by timo

  • Triage Stage changed from Unreviewed to Accepted

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 13 months ago by bendavis78

  • 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.

https://github.com/django/django/pull/2323

comment:4 Changed 12 months ago by anonymous

Has there been any update on this?

Thanks,
Dan

comment:5 Changed 11 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 16afffffe87bf8b7de6403329937433ac5096697:

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

comment:6 Changed 11 months 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 11 months ago by timo

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