Re: db API where ...or...

2008-12-15 Thread Lars Stavholm

Thanks Tim, works like a charm.
/L

Tim Chase wrote:
>> when combining Django ORM criteria you get
>> the "...WHERE...AND..." clauses.
>>
>> How do I get the "...WHERE...OR..." clauses?
>>
>> Resorting to raw SQL?
> 
> 
> Use Q objects and OR them together:
> 
> http://www.djangoproject.com/documentation/models/or_lookups/
> 
> 
> Foo.objects.filter(
>Q(field1='baz') |
>Q(field1='bar') |
>Q(field2='spatula')
>)
> 
> 
> They should be groupable as well, so you can use
> 
>filter(
>  (Q(field1='foo') & Q(field2='bar'))
>  | Q(field1='baz')
>  )
> 
> -tim
> 
> 
> 
> 
> > 
> 



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: db API where ...or...

2008-12-15 Thread Tim Chase

> when combining Django ORM criteria you get
> the "...WHERE...AND..." clauses.
> 
> How do I get the "...WHERE...OR..." clauses?
> 
> Resorting to raw SQL?


Use Q objects and OR them together:

http://www.djangoproject.com/documentation/models/or_lookups/


Foo.objects.filter(
   Q(field1='baz') |
   Q(field1='bar') |
   Q(field2='spatula')
   )


They should be groupable as well, so you can use

   filter(
 (Q(field1='foo') & Q(field2='bar'))
 | Q(field1='baz')
 )

-tim




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: db API where ...or...

2008-12-15 Thread Alex Koshelev
http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects


On Mon, Dec 15, 2008 at 18:35, Lars Stavholm  wrote:

>
> Hi all,
>
> when combining Django ORM criteria you get
> the "...WHERE...AND..." clauses.
>
> How do I get the "...WHERE...OR..." clauses?
>
> Resorting to raw SQL?
>
> Kinda' lost, any input appreciated
> /Lars
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



db API where ...or...

2008-12-15 Thread Lars Stavholm

Hi all,

when combining Django ORM criteria you get
the "...WHERE...AND..." clauses.

How do I get the "...WHERE...OR..." clauses?

Resorting to raw SQL?

Kinda' lost, any input appreciated
/Lars


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---