﻿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
33399	Overriding Choices for a field in the Form not working when using ModelForm | Django 3.2	Swaroop P	nobody	"Hi All

Facing the following issue after migrating to 3.2. 

Example:

class SomeModel(models.Model):
       field1 = models.CharField(choices=[])

class SomeModelForm(forms.ModelForm):

     __init__(*args, **kwargs):
         super().__init__(*args **kwargs)
         self.fields['field1'] = <some choices dynamically generated>

    class Meta:
         model = SomeModel
         fields = [ 'field1' ]


In the above case any choice selected is shown with the error ""not a valid choice"" this is happening because model fields is revalidated again  in modelform._post_clean() function. 
 
Intermediate solution is to remove choices from modelfield and reinitalize field in form __init__ wiht dynamic choices. But In previous versions We had choices to only override some attributes of a field rather than reinitalizing whole field. 

Thanks

"	Uncategorized	new	Forms	3.0	Normal		modelform		Unreviewed	0	0	0	0	0	0
