#33321: Django admin doesn't render "add another / modify" icons next to
ForeignKey
fields that are declared in the ModelForm
-------------------------------+--------------------------------------
Reporter: James Pic | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------+--------------------------------------
Changes (by Carlton Gibson):
* status: new => closed
* resolution: => wontfix
Comment:
Hi James.
> BUT, it won't if my field is declared in the ModelForm...
Yes. So, this is the standard (and expected) behaviour for this kind of
generation: if you declare the field yourself, then that's what you get.
The same applies to ModelForms, DRF serialisers, django-filter FilterSets,
and I would expect everything else similar: it comes up on DRF as ''Why
was my `read_only_field` not applied to my explicitly defined serialiser
field?''
The relevant docs are the extended note in the
[https://docs.djangoproject.com/en/3.2/topics/forms/modelforms
/#overriding-the-default-fields Overriding the default fields section of
the ModelForms topic docs]. It says more but:
> The fields that are automatically generated depend on the content of the
Meta class and on which fields have already been defined declaratively.
Basically, ModelForm will only generate fields that are missing from the
form, or in other words, fields that weren’t defined declaratively.
To me, it would be deeply surprising if we were to change the behaviour
for the admin here: ''You get the field you declare except in this case''
is going to be more difficult to reason about in aggregate.
If I wanted to address this in my project, I'd probably look overriding
`ModelAdmin.get_form()`, rather than pulling knowledge of
`RelatedFieldWidgetWrapper ` into `forms/models.py`.
--
Ticket URL: <https://code.djangoproject.com/ticket/33321#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/062.dcae0d9f9273db0f8cae74b6fc152f06%40djangoproject.com.