Re: union of two QuerySets

2012-08-06 Thread Robin Pedersen
There might be situations where you already have a couple of querysets, and want to combine them, or for DRYness it might be an idea to create functions that return querysets, and combine the results: combined = self.get_some() | self.get_others() And querysets are lazily executed, so unless yo

Re: union of two QuerySets

2012-08-01 Thread akaariai
On 1 elo, 19:15, Tim Chase wrote: > On 08/01/12 10:28, lex P rez wrote: > > > Hi, > > > it's better  Person.objects.filter(models.Q(first_**name__startswith='mic'), > > models.Q(first_**name__startswith='joh')) > > (only one query...) > > I'm pretty sure this will get you the intersection (it uses

Re: union of two QuerySets

2012-08-01 Thread Tim Chase
On 08/01/12 10:28, Àlex Pérez wrote: > Hi, > > it's better Person.objects.filter(models.Q(first_**name__startswith='mic'), > models.Q(first_**name__startswith='joh')) > (only one query...) I'm pretty sure this will get you the intersection (it uses AND) rather than the union (which would be usin

Re: union of two QuerySets

2012-08-01 Thread Àlex Pérez
Hi, it's better Person.objects.filter(models.Q(first_**name__startswith='mic'), models.Q(first_**name__startswith='joh')) (only one query...) 2012/8/1 Robin Pedersen > On Monday, December 11, 2006 4:37:25 AM UTC+1, Rares Vernica wrote: >> >> Hi, >> >> What is a way to get the union of two Que

Re: union of two QuerySets

2012-08-01 Thread Robin Pedersen
On Monday, December 11, 2006 4:37:25 AM UTC+1, Rares Vernica wrote: > > Hi, > > What is a way to get the union of two QuerySets? > > Something like: > > In [6]: a = Person.objects.filter(first_name__startswith='mic') > > In [7]: b = Person.objects.filter(first_name__startswith='joh') > > In [8]: a

Re: Union of two querysets?

2010-02-16 Thread Nick Booker
Yes you can do a union. Use the "|" (pipe) operator. union = queryset1 | queryset2 or you can replace queryset1 with the union as follows: queryset1 |= queryset2 Nick On 16/02/10 02:39, rebus_ wrote: On 16 February 2010 03:28, ydjango wrote: I have two query sets with two different wher

Re: Union of two querysets?

2010-02-15 Thread rebus_
On 16 February 2010 03:28, ydjango wrote: > I have two query sets with two different where clauses on same table > and same columns in select. Is it possible to have their union. > > I tried qryset = qryset1 + qryset2 >  It gave me - "+ unsupported operand" > > -- > You received this message becau

Re: union of two QuerySets

2006-12-12 Thread Honza Král
if you want a true union, use chain from itertools on the two querysets... On 12/11/06, Jeremy Dunck <[EMAIL PROTECTED]> wrote: > > On 12/11/06, Rares Vernica <[EMAIL PROTECTED]> wrote: > > > > Hi, > > > > I know the Q way, but actually the filter contains already a lot of Qs. > > > > I am looking

Re: union of two QuerySets

2006-12-11 Thread Jeremy Dunck
On 12/11/06, Rares Vernica <[EMAIL PROTECTED]> wrote: > > Hi, > > I know the Q way, but actually the filter contains already a lot of Qs. > > I am looking for a way to combine "a" and "b" without going into their > filters. QuerySets are lazy. There's no downside to combining two arbitrarily-com

Re: union of two QuerySets

2006-12-11 Thread Rares Vernica
Hi, I know the Q way, but actually the filter contains already a lot of Qs. I am looking for a way to combine "a" and "b" without going into their filters. Thanks Jacob Kaplan-Moss wrote: > On 12/10/06 9:37 PM, Rares Vernica wrote: >> What is a way to get the union of two QuerySets? > > See

Re: union of two QuerySets

2006-12-10 Thread Jacob Kaplan-Moss
On 12/10/06 9:37 PM, Rares Vernica wrote: > What is a way to get the union of two QuerySets? See http://www.djangoproject.com/documentation/db_api/#complex-lookups-with-q-objects. > In [6]: a = Person.objects.filter(first_name__startswith='mic') > > In [7]: b = Person.objects.filter(first_name