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
Pull Requests:7723 unmerged, 6368 unmerged

Description (last modified by James Pic)

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
            }
        )

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.

Change History (1)

comment:1 by James Pic, 9 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top