Opened 9 years ago
Last modified 3 years ago
#26369 new New feature
Allow override of hardcoded defaults in model Field.formfield() — at Initial Version
Reported by: | James Pic | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | James Pic, hv@…, Kevin Brown | Triage Stage: | Someday/Maybe |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Pull Requests: | |||
Description ¶
Currently, the model field defines the default form field that's used
by the modelform metaclass. It would be nice if we could override this.
For example, if a Radio widget should be used by default for a OneToOne field:
class TestModel(models.Model): name = models.CharField(max_length=200) test = models.OneToOneField( 'self', null=True, blank=True, related_name='related_test_models', # This seems like it would always be useful formfield_defaults={ 'widget': forms.RadioSelect } )
Example (incomplete) patch: https://github.com/jpic/django/commit/d102f362f3c1ceaf2d5224d71f788c0821a481ae
According to the ticket's flags, the next step(s) to move this issue forward are:
Unknown. The Someday/Maybe triage stage is used to keep track of high-level ideas or long term feature requests.
It could be an issue that's blocked until a future version of Django (if so, Keywords will contain that version number). It could also be an enhancement request that we might consider adding someday to the framework if an excellent patch is submitted.
If you're interested in contributing to the issue, raising your ideas on the Django Forum would be a great place to start.