Django Filtering System with django-filter - Filter Queryset (2018)

  Рет қаралды 116,169

The Dumbfounds

The Dumbfounds

Күн бұрын

In this tutorial you will learn how to implement a filtering system with django using the django-filter package.
7 Tips For Getting Better At Django:
mailchi.mp/dea...
Starting point for this tutorial:
github.com/Rec...
First, we will enable filtering using a model's fields, and afterwards we will implement our own custom field for changing the ordering of our queryset.
You will be installing the package using 'pip install django-filter'.
Afterwards, you will learn how to create a FilterSet and specify the fields to use in our form inside of the Meta class. Then, we will create a new SnippetFilter instance and pass it to our context.
In our template, we will use filter.qs to loop over the queryset.
If you enjoyed this video, make sure to subscribe and share it with anyone you think could enjoy it as well.
I hope to see you inside of the next episode,
Cheers.

Пікірлер: 95
@thedumbfounds767
@thedumbfounds767 6 жыл бұрын
quick addition: if you don't need to do anything fancy in your view, you can save yourself time by using the generic FilterView class inside of django_filters.views!
@Frank.lin23
@Frank.lin23 5 жыл бұрын
Xvr
@ritikajaiswal6380
@ritikajaiswal6380 5 жыл бұрын
what should i do if i don't want to display my data before filtering it?
@sebastiandrozd233
@sebastiandrozd233 4 жыл бұрын
@@PlusTres and you?
@suyogbhere328
@suyogbhere328 2 жыл бұрын
big thanks for this vedio
@emma-louisenewman7083
@emma-louisenewman7083 4 жыл бұрын
Been through so many different tutorials and this is absolutely spot on for using django-filters in CBVs. Thanks!!
@lawesosah9214
@lawesosah9214 5 жыл бұрын
This was excellent. I spent hours trying to do the same thing... in a much more complicated way. You made it so simple! Thanks a lot!!!
@olgao.614
@olgao.614 3 жыл бұрын
Thanks to! This video helped me a lot!
@Tastycurried
@Tastycurried Жыл бұрын
This was excellent 👌
@Richard-jk5iq
@Richard-jk5iq 5 жыл бұрын
This tutorial is so helpful, it saved my life! Thank you!
@zanazanelol
@zanazanelol 4 жыл бұрын
Mine too!!!! Subscribed before taking a new breath!!! May the Universe give you back tenfold!
@vaios6317
@vaios6317 3 жыл бұрын
one thing i have to say. GOD BLESS YOU !
@WillianMaiaGoulart
@WillianMaiaGoulart 4 жыл бұрын
Thanks guy, its was helpful !!!!
@devnextbd
@devnextbd 3 жыл бұрын
Very helpful for us....
@reksmeyok1957
@reksmeyok1957 3 жыл бұрын
You help me a lot with this video. Thank you.
@wallride2wallride
@wallride2wallride 2 жыл бұрын
I like it a lot; spent hours diggint thru useless content! do you feel it's still valid for django 4 behaviour? Thank you!
@Karenms92
@Karenms92 6 жыл бұрын
This tutorial saved my life! thanks!!
@thedumbfounds767
@thedumbfounds767 6 жыл бұрын
Yay!
@Karenms92
@Karenms92 6 жыл бұрын
how would you implement pagination with django-filter?, because pagination_by attribute of ListView not working
@thedumbfounds767
@thedumbfounds767 6 жыл бұрын
@@Karenms92 it should be paginate_by, not pagination_by :)
@patrickknows2296
@patrickknows2296 4 жыл бұрын
Thank you Mr Sniffit
@karstencollins6966
@karstencollins6966 3 жыл бұрын
Amazing! This is so helpful.
@erfankarimian5752
@erfankarimian5752 3 жыл бұрын
hi I write just like you and it works i want to know how can I handle paginate with django-forms i got confused
@ali-g8217
@ali-g8217 4 жыл бұрын
Thank you very much !! But could you please tell me how to customize the queryset url ? How to hide the non used filters from the url ? When I’m not searching in body in the url we get example.com/?title=x&body=
@tydatguy
@tydatguy 4 жыл бұрын
Did you ever figure this out?
@smiley2474
@smiley2474 3 жыл бұрын
thank u so much bro
@LucienDadaKYABU
@LucienDadaKYABU 4 жыл бұрын
THANK YOU VERY VERY VERY MUCH THAT IS ALL I NEEDED
@MarceloAgostonSchrotlin
@MarceloAgostonSchrotlin 5 жыл бұрын
Thanks man! it's was very helpful!! i have learned a lot! thanks again!
@arekkarczewski8228
@arekkarczewski8228 3 жыл бұрын
@the dumbfounds how can I connect filter-pagination-order with django-filter only on classes" listviews-filterset- with filter dates greater than and lower than of field with dates and with widged to select d-m-y. Can you help with that ?
@kaumsatria7981
@kaumsatria7981 5 жыл бұрын
how to change default django admin theme ? any video or some tutorial to do it ?
@MartinOru
@MartinOru 6 жыл бұрын
Just what i have been looking for. How would you implement pagination for CBV with django-filter
@thedumbfounds767
@thedumbfounds767 6 жыл бұрын
@@MartinOru there is a generic FilterView. However, I don't know if it has the paginate_by attribute. If it doesn't, you can use a ListView with the paginate_by attribute, and just implement the filtering manually.
@niteshrawat576
@niteshrawat576 6 жыл бұрын
Hey man, can you explain further on how to mimic filterset with manual filtering so that i can apply pagination to it (thats my real goal). I am just real bad on this one.
@modhaffermodhaffer
@modhaffermodhaffer 5 жыл бұрын
@@thedumbfounds767 I am facing the same problem. Cannot get proper pagination. It lists the found results, then starts listing all the objects of the model. If it is possible to give an example of pagination, we would be very grateful.
@Nioxs
@Nioxs 5 жыл бұрын
Awesome video, it's so easy to understand :)
@jacobmartin6686
@jacobmartin6686 6 жыл бұрын
u r the real MVP
@thedumbfounds767
@thedumbfounds767 6 жыл бұрын
High five!
@opencodigo
@opencodigo 3 жыл бұрын
hii ! the bootstrap in for filter.form not working. Why? I'm using bootstrap 5.
@EddyTriedCoding
@EddyTriedCoding 5 жыл бұрын
helpful. Keep it rolling.
@thedumbfounds767
@thedumbfounds767 5 жыл бұрын
Thx Edgar :)
@chromebook2447
@chromebook2447 4 жыл бұрын
If i had a multiple name fields in my database(ex. First Name & Last Name), how would i be able to make both fields searchable from one search bar instead of having 2 separate search fields on the page? Would you happen to know or be able to point me to the appropriate documentation? Great video btw!
@iandthopper
@iandthopper 5 жыл бұрын
Extremely helpful.
@mohamedrashidey8027
@mohamedrashidey8027 5 жыл бұрын
Should I save all this command or what can I do to understand..help
@AngelHernandez-ex7ji
@AngelHernandez-ex7ji 3 жыл бұрын
is there a way to render a just specific field?
@elonarbiture5691
@elonarbiture5691 5 жыл бұрын
I got this working but I'm curious how you could easily keep the full list from appearing until after you filter the results? In other words, don't display anything until you actually apply the filter? Thank you.
@franciscovinuesa7908
@franciscovinuesa7908 3 жыл бұрын
last part not working ! somehow it shows always the same query not changing by ascending or descending filters
@SumitGupta-uq8og
@SumitGupta-uq8og 4 жыл бұрын
Thank You...
@jacintacoe9626
@jacintacoe9626 5 жыл бұрын
AWESOME... Thanks so much!
@ЕвгенийМарьянов-й8р
@ЕвгенийМарьянов-й8р 4 жыл бұрын
CSS don't work, because there is no static directory in your github repo) Thanks for you video!
@guillermoreyes5495
@guillermoreyes5495 4 жыл бұрын
This way the view is returning 2 querysets, one filtered by SnippetFilter and another generated by the default get_queryset method of ListView. I think you should overwrite the get_queryset method or use FilterView as mentioned below. Thank you.
@viswanathanl215
@viswanathanl215 6 жыл бұрын
Hi. Thanks for the video. I have a doubt. How to add calender for date wise filter in admin sidebar?
@thedumbfounds767
@thedumbfounds767 6 жыл бұрын
If you want to add a filter into the admin view only, take a look at my video about the admin view.
@Thesrik23
@Thesrik23 6 жыл бұрын
Nice one Gabriel! Next video topic??
@thedumbfounds767
@thedumbfounds767 6 жыл бұрын
Srikant thank you. The next video will be about customizing the admin view!
@Thesrik23
@Thesrik23 6 жыл бұрын
The Dumbfounds Great Man.
@NaisDeis
@NaisDeis 2 жыл бұрын
It says "django_filters" is not accessedPylance, I dont know what to do, i cant import it, please help!
@ivankir9716
@ivankir9716 4 жыл бұрын
bro, thank you so much!
@Skaxarrat
@Skaxarrat 6 жыл бұрын
This tutorial saved my life! Or at the very least, a day or two of doing this manually at my job. It is possible to use django-filters with Ajax so we don't have to reload the page?
@thedumbfounds767
@thedumbfounds767 6 жыл бұрын
Sure, I guess you could use javascript to construct the parameters list based on the values that were entered into the input fields of a form. Then, you could send an AJAX request to your ajax view url and append the GET parameters string you previously constructed using javascript. In the view, you can use the filter just like shown in the video. That view would need to return a serialized version of the objects, which is fairly easy to do, even without using the DRF. Take a look at this for serialization: docs.djangoproject.com/en/2.0/topics/serialization/#serializing-data
@adam_balkoev
@adam_balkoev 6 жыл бұрын
Is it possible to automatically refresh the page when you select a filter, can you give an example? Thanks for video, like!
@5starkarma
@5starkarma 5 жыл бұрын
AJAX
@jonesmutua501
@jonesmutua501 5 жыл бұрын
i really need your help, how would you show the results of the filter in a result view, not the same page as you have done? please help
@arnabjyotithakuria7469
@arnabjyotithakuria7469 4 жыл бұрын
How to implement in checkbox.. please help
@sabali8647
@sabali8647 3 жыл бұрын
Why did you stop creating content?
@thedumbfounds767
@thedumbfounds767 3 жыл бұрын
Both because of time reasons and I wasn't happy with the type of content I created. Planning on a different set of videos for the far future tho!
@fosbergaddai4996
@fosbergaddai4996 2 жыл бұрын
The message i got was No module named 'django_filters' how do I go about it
@terrencegivens8519
@terrencegivens8519 4 жыл бұрын
I'm very late to the party but I want to filter without touching the template. Is there a way to do this?
@boryskuczkowski
@boryskuczkowski 6 жыл бұрын
What would be an elegant way of searching through both title and body using one search field?
@thedumbfounds767
@thedumbfounds767 6 жыл бұрын
Don't know if django-filter has that functionality built-in. For a custom solution, you can use Q objects. Something like this (untested): Snippet.objects.filter(Q(title__icontains=searchterm) | Q(body__icontains=searchterm)) Does that help?
@boryskuczkowski
@boryskuczkowski 6 жыл бұрын
@@thedumbfounds767 yep, I worked it out almost the same way, no need to use django-filter at all, just import q from django.db. Thanks for your answer!
@bikersview9926
@bikersview9926 5 жыл бұрын
I face an issues it's not shown filter.form|bootstrap doesn't show any form
@dpaudiovisual1698
@dpaudiovisual1698 4 жыл бұрын
I want to set an inline form and without field names
@czanki
@czanki 4 жыл бұрын
I am new to python and django. I am trying to filter List by date range set by web user (from, to). To be honest I thought it is kinda obvious thing to do, but I have real hard time to find any solution for that. In addition I want to use tempusdominus so users would be able to put dates in friendly looking way. Maybe making a video on how to filter queryset by dates provided by user would be a good idea for others also? Thank you for this video, it helped mi a lot with making search field!
@footlesscat8016
@footlesscat8016 2 жыл бұрын
did u find it?
@ahmedmashaly2
@ahmedmashaly2 Жыл бұрын
it is great but still there are problem in pagination with filtering
@EddyCaffrey
@EddyCaffrey 6 жыл бұрын
Great. Thanks. 👍🏽👍🏽👍🏽
@thedumbfounds767
@thedumbfounds767 6 жыл бұрын
👍👍
@runnerwannabe90
@runnerwannabe90 4 жыл бұрын
Late to the party I know. Can I ask, why would you want to do this, as opposed to using Model Managers?
@kroloskar
@kroloskar 6 жыл бұрын
Hi, do you know Elasticsearch? Could you show how to make eBay-like (frontend) search filters using Elasticsearch? Thanks for nice tutorials! :)
@thedumbfounds767
@thedumbfounds767 6 жыл бұрын
Hey, I don't know Elasticsearch, yet. But thanks for the suggestion!
@bikersview9926
@bikersview9926 5 жыл бұрын
Please any help me...{{filter }} shows objects But here is the problem {{filter.form}} Comes nill blank What ws the problem my one suggest mee
@jackyng2375
@jackyng2375 4 жыл бұрын
greattt
@AlexWinkler
@AlexWinkler 4 жыл бұрын
How would I filter something like context['user_count'] = User.objects.all().count()
@JesusGil90
@JesusGil90 6 жыл бұрын
cool
@thedumbfounds767
@thedumbfounds767 6 жыл бұрын
Thanks!
@brotherx6205
@brotherx6205 5 жыл бұрын
I'm getting an error "invalid filter: bootstrap" can anyone help?
@modhaffermodhaffer
@modhaffermodhaffer 5 жыл бұрын
Load bootstrap tags in ur html template or use crispy forms
@martiruda
@martiruda Жыл бұрын
Understood 0 but i can replicate your code.
@joshuasalinashernandez9068
@joshuasalinashernandez9068 6 жыл бұрын
you said "Hey, You, Hola"? Jajaja
@thedumbfounds767
@thedumbfounds767 6 жыл бұрын
Hey you all :)
@Manda-ik3ud
@Manda-ik3ud 6 жыл бұрын
keyboard voice
@thedumbfounds767
@thedumbfounds767 6 жыл бұрын
lol
@ramiz3570
@ramiz3570 4 жыл бұрын
+
@nomoredrama2992
@nomoredrama2992 6 жыл бұрын
I am wondering if I can apply this to query using search forms. My model has 3 FK fields along other fields and I want the user to select or type those 3 fields in the search form and if there is record they will get the record(leads to another page)
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН
Правильный подход к детям
00:18
Beatrise
Рет қаралды 11 МЛН
How Model Queries Work in Django
27:47
Pretty Printed
Рет қаралды 95 М.
Django REST API Tutorial - Filtering System #4 (2018)
5:10
The Dumbfounds
Рет қаралды 20 М.
I Spent 100 Hours Inside The Pyramids!
21:43
MrBeast
Рет қаралды 53 МЛН
Why I Use Django Function Based Views
7:58
Dennis Ivy
Рет қаралды 28 М.
Pagination For Django - Django Wednesdays #18
18:53
Codemy.com
Рет қаралды 44 М.
Django live search | live search using django and javascript
20:07
How to easily filter objects in Django
38:59
Cloud With Django
Рет қаралды 1,8 М.
Solving one of PostgreSQL's biggest weaknesses.
17:12
Dreams of Code
Рет қаралды 228 М.