Javaaaa
Javaaaa

Reputation: 3804

Django model filter: needs to filter two columns

So I have this model Game that has an Awayteam and Hometeam field. Now I want to get all the games of a certain club. So I need to get all objects in which my club is an away team or a hometeam.

I could do: Game.object.filter(hometeam=myteam) and a a seperate Game.object.filter(awayteam=myteam) query.
However, can I combine these queries into one with django?

Upvotes: 1

Views: 148

Answers (1)

second
second

Reputation: 28637

for "OR" queries, you want to have a look at Q objects

Upvotes: 3

Related Questions