merge django queryset objects
How to join querysets in django
Feb 6, 2022
lets learn how to merge two or more models data into one object with the help of itertools
In views.py just write
from itertools import chaindef myfunc(request):
data1 = model1.objects.all()
data2 = model2.objects.all()
combined_data = list(chain(data1,data2))
print(combined_data) return httpresponse("success")
and then you can iterate over the result object . you can use this method to combine more than two objects also .