Adding Filters to the List Screen
  
    00:00
  
  
  Adding Filters to the List Screen. In addition to filtering data on the change list through the calling URL, you can also filter with a built-in widget. Add the list_filter attribute to the CourseAdmin object in core/admin.py.
  
    00:25
  
  
  The list_filter will display a new section on the page with a list of links. In this case, the links filter the page by year. The filter list is automatically populated with the year values used by the Course objects in the database. Clicking a year on the right-hand side will change the list to only include Course objects with that year value.
  
    00:47
  
  
  You can also filter based on the attributes of related objects using the dunder (__) field lookup syntax. For example, you could filter GradeAdmin objects by course__year, showing the Grade objects for only a certain year of courses.
  
    01:06
  
  
  If you’re looking for more control over your filtering, then you can even create filter objects that specify the lookup attributes and the corresponding QuerySet. Being able to filter data is useful, but being able to search brings true power and convenience.
Become a Member to join the conversation.
