Last active
August 29, 2015 14:18
-
-
Save robdmc/e14679d3102605928d6d to your computer and use it in GitHub Desktop.
Queryset chunker for values queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def chunk_values_queryset(queryset, chunksize): | |
if queryset.count() > 0: | |
ending_pk = queryset.aggregate(Min('id'))['id__min'] - 1 | |
out = ['dummy'] | |
while len(out) > 0: | |
out = list(queryset.filter(pk__gt=ending_pk).order_by('id')[:chunksize]) | |
if out: | |
ending_pk = out[-1]['id'] | |
yield out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment