August 2016
Beginner to intermediate
717 pages
15h 24m
English
What happens if you want to show category selection in a form? How will the hierarchy be presented? In django-mptt, there is a special TreeNodeChoiceField form field that you can use to show the hierarchical structures in a selected field. Let's take a look at how to do this.
We will start with the movies app that we defined in the previous recipes.
Let's create a form with the category field and then show it in a view:
forms.py file of the app, create a form with a category field as follows:
# movies/forms.py # -*- coding: UTF-8 -*- from __future__ import unicode_literals from django import forms from django.utils.translation import ugettext_lazy as _ ...Read now
Unlock full access