In this example, the override will also apply to a `CustomField` field on
the model.
{{{#!python
class CustomField(models.TextField):
...
class SomeModelAdmin(admin.ModelAdmin):
formfield_overrides = {
models.TextField: {"widget": forms.Textarea},
}
}}}
In my situation I am using a custom bleached field that sets a different
default widget in its `formfield` method and it is counterintuitive to me
that overriding `TextField` also overrides the custom implementation. I
expect that it would only override fields matching the class precisely,
ie, override fields declared as `TextField` instances but not those
declared as `CustomField`.
The code that implements this behaviour is
`BaseModelAdmin.formfield_for_dbfield()` which traverses the MRO looking
for any matching overrides.
https://github.com/django/django/blob/master/django/contrib/admin/options.py#L179-L184
I discovered it working with 2.2. The code looks unchanged from 2.2 to
master, although I haven't tested in master.
If there is no appetite to change this behaviour, could break some folk's
implementations, a note in the docs would be nice.
--
Ticket URL: <https://code.djangoproject.com/ticket/31741>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => wontfix
Comment:
It is expected behavior, see #10059.
[https://docs.djangoproject.com/en/3.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_overrides
Docs] improvements are always welcome, please feel-free to send PR with
clarification.
--
Ticket URL: <https://code.djangoproject.com/ticket/31741#comment:1>
Comment (by Mark Gregson):
It's unfortunate that these different use-cases for creating custom model
fields are not handled equally well by the admin options, but thanks for
the information, I'll have a look at writing a note for the docs.
--
Ticket URL: <https://code.djangoproject.com/ticket/31741#comment:2>