[PYTHON] [Django] Give an initial value to ChoiceField

environment Python 3.5.0 Django 1.9.2


    (1, 'Strawberry cake'),
    (2, 'Chocolate cake'),
    (3, 'Cheesecake')

class CakeForm(forms.Form):
	medal = ChoiceField(widget=Select, choices=MEDAL_CHOICES)
	class Meta:
		model = Cake


cake_form = CakeForm(initial = {
	'selected_cake': 2	#Set chocolate cake to default

Recommended Posts

[Django] Give an initial value to ChoiceField
[Django] Give Form a dynamic initial value from Model
Django initial setup up to Intellij Debug
unable to import django
update django version 1.11.1 to 2.2
[Django] How to give input values in advance with ModelForm
How to do the initial setup from Django project creation
How to check if a value exists in an enum
[Django] Memo to create an environment of Django + MySQL + Vue.js [Python]
Relationship between Bound / Unbound and initial value of Django2 Form