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

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

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top