Have a look at this question fields and base_fields - Django. I want to do the exact stuff, except I need to set the initial for this field instead of choice. Even I have swap the order of lines also as mentioned in the answer of that question, but I am not getting the initial set value at frond end. mean while when I tried to check the code with pdb
, I was getting no error and value also set to 5 successfully
class NewFlatpageForm(FlatpageForm):
template_name = forms.ChoiceField(choices = [])
def __init__(self, *args, **kwargs):
super(NewFlatpageForm, self).__init__(*args, **kwargs)
self.base_fields['template_name'].initial = 5