Opened 9 years ago
Last modified 3 years ago
#26369 new New feature
Allow override of hardcoded defaults in model Field.formfield() — at Version 1
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 |
Description (last modified by )
Currently, the model field builds the default form field that's used
by the modelform metaclass in Field.formfield(). It uses hardcoded defaults which it would be nice to be able to override with attributes.
Example patch: https://github.com/jpic/django/commit/d102f362f3c1ceaf2d5224d71f788c0821a481ae
This patch allows to use Radio widget 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 } )
Note:
See TracTickets
for help on using tickets.