+----+---------+-----------+---------------------+-----------+-----------+
| id | user_id | foo_id | created_at | active |type |
+----+---------+-----------+---------------------+-----------+-----------+
| 1 | 1 | 1 | 2011-05-10 13:12:35 | 1 | 2 |
| 7 | 5 | 2 | 2011-05-10 14:45:04 | 1 | 1 |
| 4 | 4 | 2 | 2011-05-10 13:24:45 | 1 | 2 |
| 8 | 6 | 2 | 2011-05-16 14:53:03 | 1 | 1 |
| 9 | 7 | 2 | 2011-05-16 14:55:11 | 1 | 0 |
+----+---------+-----------+---------------------+-----------+-----------+
This is a UserMapper model in django.
I want to write a query such that:
Get all the user_id whose foo_id = 2 and type=0 and all the result of user_id = 6;
Say;
select * from table where user_id = 6 and (foo_id=2 and type=6) // Such sort of query
How can I do in django query set..
If you mean
user_id=6 and type=6 and food_id=2, then just use:if you mean (
user_id=6)or(type=6 and food_id=2), you can use theQobject :See more about
Qobject here: http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects