August 2016
Beginner to intermediate
717 pages
15h 24m
English
If you want the administrators to be able to filter the change list by date, relation, or field choices, you need to use the list_filter property for the admin model. Additionally, there is a possibility of having custom-tailored filters. In this recipe, we will add a filter that allows you to select products by the number of photos attached to them.
Let's start with the products app that we created in the previous recipe.
Execute the following two steps:
admin.py file, create a PhotoFilter class extending from SimpleListFilter, as follows:
# products/admin.py # -*- coding: UTF-8 -*- # ... all previous imports go here ... from django.db import models class PhotoFilter(admin.SimpleListFilter): ...Read now
Unlock full access