Using a checkbox list to choose multiple categories in forms

When more than one category needs to be selected in a form, you can use the TreeNodeMultipleChoiceField multiple selection field that is provided by django-mptt. However, multiple selection fields are not very user-friendly from GUI point of view as the user needs to scroll and hold the control keys while clicking in order to make multiple choices. That's really awful. A much better way will be to provide a checkbox list to choose the categories. In this recipe, we will create a field that allows you to show the indented checkboxes in the form.

Getting ready

We will start with the movies app that we defined in the previous recipes and also the utils app that you should have in your project. ...

Get Web Development with Django Cookbook - Second 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.