#33574 closed Bug (wontfix)
SlugField in formfield_overrides
Reported by: | Maxim Danilov | Owned by: | SaNjU Saini |
---|---|---|---|
Component: | contrib.admin | Version: | 4.0 |
Severity: | Normal | Keywords: | admin, modeladmin, documentation |
Cc: | SaNjU Saini | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
ff overriding not always works in ModelAdmin.
For example, I want to have a possibility to override form field class, like that:
formfield_overrides = { models.SlugField: {'form_class': forms.CharField} }
its is not possible, error is "class CharField receive too much arguments in init".
And all Django Fields with additional arguments give us this error, if somebody want to override field_class, like in options.py in FORMFIELD_FOR_DBFIELD_DEFAULTS
I think formfield_overrides was a wrong decision, but we have it already. And in Documentation is not deprecated to use "form_class", that's why we should to describe about "possible errors after field_class overriding" in documentation.
Change History (4)
comment:1 by , 3 years ago
Cc: | added |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 3 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
comment:3 by , 3 years ago
I think, it simply can be added in documentation in box "warning", we already have this box.
I know Django a little bit, of course, i can change my field in many places: in form class, in get_form method, in formfield_for_db.
Simplest way is to use "formfield_overrides", this is an attribute. But, it is not well documented.
That's why i have started this issue and i think we should to describe about "possible errors after field_class overriding" in documentation.
comment:4 by , 3 years ago
If you'd like to propose a documentation patch, then please do.
My concern would be that that it would be difficult to explain clearly, such that it's not of benefit to add for most readers, however very happy to consider!
Interesting example, but out of scope for
formfield_overrides
, which is just a quick-and-dirty way to override some of the Field options for use in the admin (emphasis added).If you really want to use CharField here, provide a Form subclass via
ModelAdmin.get_form()
. (Adding logic to excludekwargs
viaformfield_overrides
is not going to be worth the complexity.)