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 + b
Thanks a lot,
Ray
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__startswith='joh')
Try::
>>> Person.objects.filter(
... Q(first_name__startswith="mic") |
... Q(first_name__startswit="joh")
... )
Jacob
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
QuerySets are lazy. There's no downside to combining two
arbitrarily-complex querysets either before or after the filter
call(s).
--
Honza Král
E-Mail: Honza...@gmail.com
ICQ#: 107471613
Phone: +420 606 678585
--
Try:
a | b
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/ie69j4ewJNUJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.