Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Basics Final Details Step Detail View

What is the best way for building query filters in Django?

I have something like this:

http://i.imgur.com/BPpmf.png

In the models.py not only Boolean fields but also a selectField, a charField and textField. At the time I'm trying to figure out how to build a proper query filter (including a blank value), in which, the user is the one who decides.

At the time I have seen some old answers to this problem but I'm not actually sure how to do it. The alternatives are:

  1. Using a class based filter like this (answer is from 2009):

https://github.com/alex/piano-man/blob/db6f723dfc15155d7b2f900519d6ca3292a95f76/piano_man/tickets/filters.py

  1. Using raw queries in Django

  2. Using Django Restful (allow to exclude empty values)

  3. Using Django sessions (Need to figure out how first)

Have anyone experienced something similar?

1 Answer

In order to answer this. I have found a reusable application inside Django:

http://django-filter.readthedocs.org/en/stable/index.html

We also need to use Django forms.

Can't wait for the next Django Course!