Filtering through whole way from template to CBV and back.

Guys, please, what is the best way to implement filtration. I mean is quite clear how to filter queryset in django view but whole process is not that clear. :thinking:
For example I need to dynamically filter my objects list by year and month, also I should use only years and months that related to the original full queryset (from oldest to newest) not any random year.
In django admin we have a quite cool ModelAdmin.date_hierarchy mechanism but I need it not in admin site! Can i use it in my own templates and views and how? :roll_eyes:
If I can not, how is the best way to do this? Should I use form and pass args through GET parameters? Or maybe use django forms would be better? Any thoughts? Please! :nerd_face:

Take a look at django-filter which is for exactly this:

https://django-filter.readthedocs.io/en/main/

You define a FilterSet, using fields from your model at its most simple. You then pass it the request.GET data (the query parameters) and it handles both validation and filtering.

Thanks, I’ll definitely dig in into django-filters. Perhaps this what i really need. I just thought that django has its own mechanism to stuff like this, but it seems not really ))) Thanks for your help!