38👍
✅
from itertools import chain
report = chain(ledger, journal)
Itertools for the win!
If you want to do an Union, you should convert these querysets
into python set
objects.
If it is possible to filter the queryset itself rightly, you should really do that!
8👍
Use itertools.chain:
from itertools import chain
report = list(chain(ledger, journal))
Note: you need to turn the resulting object into a list for Django to be able to process it.
- [Django]-A QuerySet by aggregate field value
- [Django]-110: Connection timed out (Nginx/Gunicorn)
- [Django]-Django: What are the best practices to migrate a project from sqlite to PostgreSQL
2👍
I had the same issue. I solved it using the union method combined_queryset = qs1.union(qs2)
Using your example: report = ledger.union(journal)
- [Django]-Django serve static index.html with view at '/' url
- [Django]-Django models – how to filter number of ForeignKey objects
- [Django]-Accessing a dict by variable in Django templates?
Source:stackexchange.com