Howto merge 2 Django QuerySets in one and make a SELECT DISTINCT Howto merge 2 Django QuerySets in one and make a SELECT DISTINCT django django

Howto merge 2 Django QuerySets in one and make a SELECT DISTINCT


It took me a while to find this

all_points = p1_points | p2_points


I am not familiar with geodjango, but combining QuerySets into one QuerySet is possible via the Q-Object and Boolean Operators. See http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects

Example:

Q(p1_points) | Q(p2_points)

I can't help you further, because I am not really sure what you are trying to accomplish.


I think Q queries can achieve what you need like this:

points = SinglePoint.objects.filter(    Q(p1_set__vektordata__order__project__slug=slug) |    Q(p2_set__vektordata__order__project__slug=slug)).distinct()