#26369: Allow override of hardcoded defaults in model Field.formfield()
-------------------------------------+-------------------------------------
Reporter: James Pic | Owner: James Pic
Type: New feature | Status: assigned
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Someday/Maybe
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by James Pic):
I'm unsure if I wouldn't prefer to just be able to define a project-level
default formfield callback, because that's going to depend on what the
INSTALLED_APPS provide. Then for example, to make all relations to Foo a
particular widget instead of Select, and to make all CharFields have a
text field:
{{{
# settings.py:
DEFAULT_FORMFIELD='project.forms.project_formfield'
# project/forms.py
def project_formfield(db_field, form_class, defaults):
if db_field.rel.to == Foo:
defaults['widget'] = forms.RadioSelect
if db_field.model == Foo and isinstance(db_field, models.CharField):
defaults['widget'] = forms.Textarea
return form_class(**defaults)
}}}
This seems even more powerful, anybody would like to take a look at such
an implementation ?
--
Ticket URL: <https://code.djangoproject.com/ticket/26369#comment:9>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/062.66bea993e42d56f9f12eda887346d31e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.