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
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
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
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
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
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
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
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
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
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
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
11 matches
Mail list logo