The Python Oracle

Filter with multiple conditions on a single related object

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Orient Looping

--

Chapters
00:00 Filter With Multiple Conditions On A Single Related Object
01:22 Accepted Answer Score 4
01:43 Answer 2 Score 3
01:54 Thank you

--

Full question
https://stackoverflow.com/questions/3834...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #django #djangoqueryset #djangoorm

#avk47



ACCEPTED ANSWER

Score 4


Edit: What you are saying is not correct. The filter() function automatically 'AND's its parameters. See the documentation on filter




ANSWER 2

Score 3


You can use Q objects to handle more complex queries. See django docs about Q objects

from django.db.models import Q

q.filter(
    Q(answer__code=code) & Q(answer__value=value)
)