[Django]-Checkboxes to select objects in Django

3👍

Django’s forms have a ModelMultipleChoiceField for that. The default widget is <select>, but you can tell it to use checkboxes instead (CheckboxSelectMultiple):

from django import forms
from <yourapp>.models import Article

class ExportForm(forms.Form):
     …
    articles = forms.ModelMultipleChoiceField(
        queryset = Article.objects.all(), # or .filter(…) if you want only some articles to show up
        widget  = forms.CheckboxSelectMultiple,
    )
👤helb

Leave a comment