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.
Execute the following two steps:
In the
admin.py
file, create aPhotoFilter
class extending fromSimpleListFilter
, as follows:# products/admin.py # -*- coding: UTF-8 -*- # ... all previous imports go here ... from django.db import models class PhotoFilter(admin.SimpleListFilter): # Human-readable title which will be displayed in the # right admin sidebar just above the filter options. title = _("photos") # Parameter for the filter that will be used in the # URL query. parameter_name = "photos...