Skip to content

Instantly share code, notes, and snippets.

@kezabelle
Created September 18, 2015 14:15
Show Gist options
  • Save kezabelle/c841c049dcf4aafd5556 to your computer and use it in GitHub Desktop.
Save kezabelle/c841c049dcf4aafd5556 to your computer and use it in GitHub Desktop.
For joshuajonah in #django IRC
>>> from django.forms import Form
>>> from django.contrib.auth import get_user_model
>>> from django.forms.models import ModelMultipleChoiceField
>>> class MyForm(Form):
>>> field = ModelMultipleChoiceField(queryset=get_user_model().objects.all())
>>> myform = MyForm(initial={'field': [1]})
>>> myform.as_p()
# this should include
# <select multiple="multiple" id="id_field" name="field">\n<option value="1" selected="selected">kezabelle</option>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment