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

∥☆過路亽.° 提交于 2019-11-30 11:08:19

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()

p1_points.union(p2_points)

See Docs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!