To render an indented list of categories with checkboxes, we will create and use a new MultipleChoiceTreeField form field and create an HTML template for this field.
The specific template will be passed to the crispy_forms layout in the form. To do this, perform the following steps:
- In the core app, add a form_fields.py file and create a MultipleChoiceTreeField form field that extends ModelMultipleChoiceField, as follows:
# myproject/apps/core/form_fields.pyfrom django import formsclass MultipleChoiceTreeField(forms.ModelMultipleChoiceField): widget = forms.CheckboxSelectMultiple def label_from_instance(self, obj): return obj
- Use the new field with the categories to choose from in a new form for idea creation. Also, in ...