Gist 641ecab96cd0c032e3e8
✓ Published0🌍 Public
Aandybak
Last edited May 8, 2014
Created on May 8, 2014
This example demonstrates a Django middleware that automatically applies predefined filters to admin changelist views. It shows how staff users are redirected to filtered list pages based on configuration in `ADMIN_DEFAULT_CHANGELIST_FILTERS`, while avoiding redirect loops by checking the HTTP referer. The code uses Django’s `HttpResponseRedirect`, `reverse`, and `settings` API, along with Python’s `sys` module for dynamic callback loading. The middleware triggers only for admin paths and supports both static values and callback functions to determine filter defaults, as seen in the `default_filter.py` file.
AI-generated description