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.
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'})
- [Answered ]-Creating file and saving in Django model (AttributeError?)
- [Answered ]-How to resize an image in Python without using Pillow
Source:stackexchange.com