[Answered ]-Setting a default value in choicfield in Django

1👍

In order to take account initial value in Django choice field, I made something like this :

form.fields['country'].initial = "what do you expect"

For example, in my script, I have :

form.fields['sex'].initial = Person.sex

In my case, Person is a Django model where all person’s informations are located.

👤Essex

1👍

When you create an instance of your form, you should pass the keyword argument initial to set an initial value for the field

form = CountryForm(initial={'country': 'An'})

Leave a comment