4👍
✅
You only need to set initial
values to your field like this:
class YourForm(forms.Form):
choices = (
('choice1':'choice1'),
('choice2':'choice2'),
('choice3':'choice3')
)
#for example if you want to select choice1 and choice2
initial_values = ['choice1', 'choice2']
field = forms.MultipleChoiceField(initial=initial_values)
1👍
Use Django ModelForm to do this. When instantiating, provide inital data to the form.
For example:
def your_view(request):
form = YourModelForm(initial={'choice_field_name': list of choices})
- [Django]-Django, how to use render_to_response with many templates
- [Django]-How can I combine two views and two forms into one single template?
- [Django]-How to secure files upload using django
- [Django]-How to access inline data in django ModelAdmin
Source:stackexchange.com