#20999: Cannot specify form_class that isn't subclass of TypedChoiceField for 
field
with choices
---------------------------------------+------------------------
               Reporter:  carljm       |          Owner:  nobody
                   Type:  New feature  |         Status:  new
              Component:  Forms        |        Version:  master
               Severity:  Normal       |       Keywords:
           Triage Stage:  Unreviewed   |      Has patch:  0
    Needs documentation:  0            |    Needs tests:  0
Patch needs improvement:  0            |  Easy pickings:  0
                  UI/UX:  0            |
---------------------------------------+------------------------
 In `Field.formfield()`, if `self.choices` is set, Django overrides any
 supplied `form_class` with `TypedChoiceField` unless the given
 `form_class` is a subclass of `TypedChoiceField`. This is unnecessarily
 restrictive (as explicit type checks usually are), and is particularly
 problematic when working with a field that takes multiple values (such as
 a Postgres array field), where `TypedMultipleChoiceField` would be the
 appropriate form field class, because `TypedMultipleChoiceField` is not a
 subclass of `TypedChoiceField`.

 Prior to the fix for #18162, Django was even more restrictive; a custom
 `form_class` was not respected at all when choices were set.

 I think the wrong fix for #18162 was chosen. The original patch provided
 by rafallo there would have respected a new keyword argument to
 `formfield()`, `form_class_for_choices`. This provides full flexibility,
 and is conceptually more correct; since a totally different form field is
 generally needed for the same db field when there are choices, a separate
 keyword argument to control this form field is appropriate. I propose that
 we switch to rafallo's fix (though I prefer the slightly shorter name
 `choices_form_class`).

 Unfortunately since the subclass check was committed and released in the
 1.6 betas, we probably still have to maintain compatibility with people
 passing a subclass of `TypedChoiceField` as `form_class` and expecting it
 to be used when choices are set.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/20999>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.a690a8b11e67c49bd6e67650c2fcf69d%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to