How to do it...

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:

  1. 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
  1. Use the new field with the categories to choose from in a new form for idea creation. Also, in ...

Get Django 3 Web Development Cookbook - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.