Using Django's changelist feature in custom views
Django has a fabulous ChangeList feature. It is used to show lists in admin. It also provides:
- Search bar
- Date Hierarchy filters
- Other filters in sidebar (including option to define custom filters)
- Handles pagination
How it works in Admin
We define a ModelAdmin
class. The ModelAdmin
class then creates a ChangeList
instance.
The ChangeList
class is responsible for filters, pagination and date hierarchy
The search functionaity is handled by ModelAdmin
class.
The ChangeList
object is then rendered in templates using admin's templatetags
. These
templatetags
are result_list
, pagination
, date_hierarchy
and search_form
.
We can re-use these template-tags in our templates too.
Idea to decouple ChangeList
If we can decouple the ChangeList
class from ModelAdmin
, then it can do wonderful things.
It might then be possible to use this class at other places. It can function just like Paginator
class.