Skip to content

Instantly share code, notes, and snippets.


esseti/ Secret

Created Mar 30, 2018
What would you like to do?
class MultipleChoiceForm(ModelForm):
class Meta:
model = MyModel
fields = ('myChoices',)
widgets = {
'myChoices': MyWidget,
def __init__(self, qs, *args, **kwargs):
# this is set in get_form_kwargs of the view
super().__init__(*args, **kwargs)
#this is needed to display only the data that matches the query
self.fields['myChoices'].queryset = qs
#this is needed for the rendering
self.fields['myChoices'].widget.qs = qs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment