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
Source:stackexchange.com