# Filtering through whole way from template to CBV and back.

**URL:** <https://forum.djangoproject.com/t/filtering-through-whole-way-from-template-to-cbv-and-back/10758>\
**Category:** Using Django\
**Created:** [December 1, 2021, 11:11am UTC](https://forum.djangoproject.com/t/filtering-through-whole-way-from-template-to-cbv-and-back/10758 "2021-12-01T11:11:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mryurka](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mryurka/32/6511_2.png) [@mryurka](https://forum.djangoproject.com/u/mryurka)\
**Post date:** [December 1, 2021, 11:11am UTC](https://forum.djangoproject.com/t/filtering-through-whole-way-from-template-to-cbv-and-back/10758/1 "2021-12-01T11:11:18Z")

</div>

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. 🤔  
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? 🙄  
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! 🤓

---

<div class="post-metadata">

**Author:** ![carltongibson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/carltongibson/32/267_2.png) [@carltongibson](https://forum.djangoproject.com/u/carltongibson)\
**Post date:** [December 1, 2021, 11:24am UTC](https://forum.djangoproject.com/t/filtering-through-whole-way-from-template-to-cbv-and-back/10758/2 "2021-12-01T11:24:15Z")

</div>

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

[https://django-filter.readthedocs.io/en/main/](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.

---

<div class="post-metadata">

**Author:** ![mryurka](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mryurka/32/6511_2.png) [@mryurka](https://forum.djangoproject.com/u/mryurka)\
**Post date:** [December 3, 2021, 2:59pm UTC](https://forum.djangoproject.com/t/filtering-through-whole-way-from-template-to-cbv-and-back/10758/3 "2021-12-03T14:59:55Z")

</div>

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!
