Background :- I am trying to merge 2 querysets from same model.
Something like this. i.e. every 3rd counter they should be merged.
queryset = get_foo(person) #First queryset
promoted_foo = get_promoted_foo() #Second queryset
for (counter,(s,p)) in enumerate(itertools.izip(queryset,promoted_foo)):
if counter%3==0:
queryset.insert(counter,promoted_foo.pop())
if promoted_foo:
queryset.extend(promoted_foo)
What is the most Pythonic way to do this ?
I know I can use list() on the quersets and then merge them. But that consumes a lot of memory. So what can be a alternative to this?
You might define your own generator that lazily loads items from the querysets.
I haven’t tested this but something like: