#26369: Allow override of hardcoded defaults in model Field.formfield()
-------------------------------------+-------------------------------------
     Reporter:  jpic                 |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Forms                |                  Version:  1.9
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by jpic):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Old 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

New description:

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

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26369#comment:1>
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.9e9724162eca38b7e4ee5d7356e73463%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to