9👍
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.
- [Django]-Difference between values() and only()
- [Django]-How to create a user in Django?
- [Django]-HTML Forms without actions
7👍
I think Q queries can achieve what you need like this:
points = SinglePoint.objects.filter(
Q(name=name) |
Q(name=name)
).distinct()
- [Django]-Gunicorn autoreload on source change
- [Django]-Django catch-all URL without breaking APPEND_SLASH
- [Django]-Django: sqlite for dev, mysql for prod?
- [Django]-Cross domain at axios
- [Django]-Testing custom admin actions in django
- [Django]-Comparing querysets in django TestCase
1👍
You can use "|"(bitwise or) to combine the querysets of the same model and distinct() and values_list() as shown below:
all_points = (p1_points | p2_points).distinct().values_list('name')
And, you can use |=
to add the queryset of the same model as shown below:
all_points = p1_points
all_points |= p2_points
all_points = all_points.distinct().values_list('name')
- [Django]-Django Rest Framework Business Logic
- [Django]-Django: Arbitrary number of unnamed urls.py parameters
- [Django]-Where to put business logic in django
Source:stackexchange.com