﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30395	Document ModelForm specifying field class corresponding to model fields with choices.	Quentin	Tobias Kunze	"If a model field has choices, `Model.formfield` will disregard the `form_class` keyword argument (plucked from `ModelForm.Meta.field_classes`), in favor of `choices_form_class`, which is not set by the ModelForm field generation machinery, and defaults to `TypedChoiceField`. As a result, the following won't work:

{{{#!python
class Language(models.Model):
    LANGUAGES = (
        ('FR', 'French'),
        ('EN', 'English')
    )
    iso = models.CharField(max_length=3, choices=LANGUAGES)

class SloppyIsoField(CharField):
    """"""Choice field that strips and uppercases language codes""""""

    def to_python(self, value):
        value = super().to_python(value)
        return value.strip().upper()

class LanguageForm(forms.ModelForm):
    class Meta:
        fields = ('iso',)
        field_classes = {
            'iso': SloppyIsoField
        }
}}}

Granted, this is a bit contrived, but it might be worth mentioning the caveat in the docs. Or maybe allow a `Meta.choices_field_classes`? If this is relevant I'd happily contribute."	Cleanup/optimization	closed	Documentation	dev	Normal	fixed	ModelForm		Accepted	1	0	0	0	0	0
