(qs, num_batches=10, min_batch_size=100000)
Returns a (start, end, total, queryset) tuple for each batch in the given
    queryset.

    Usage:
        # Make sure to order your querset
        article_qs = Article.objects.order_by('id')
        for start, end, total, qs in batch_qs(article_qs):
            print "Now processing %s - %s of %s" % (start + 1, end, total)
            for article in qs:
                print article.body
Returns a (start, end, total, queryset) tuple for each batch in the given
    queryset.
Returns a ( start end total queryset ) tuple for each batch in the given queryset .
def batch_qs(qs, num_batches=10, min_batch_size=100000):
    """
    Returns a (start, end, total, queryset) tuple for each batch in the given
    queryset.

    Usage:
        # Make sure to order your querset
        article_qs = Article.objects.order_by('id')
        for start, end, total, qs in batch_qs(article_qs):
            print "Now processing %s - %s of %s" % (start + 1, end, total)
            for article in qs:
                print article.body
    """
    total = qs.count()
    if total < min_batch_size:
        batch_size = total
    else:
        batch_size = int(total / num_batches) or total
    for start in range(0, total, batch_size):
        end = min(start + batch_size, total)
        yield (start, end, total, qs[start:end])
def batch_qs ( qs , num_batches = 10 , min_batch_size = 100000 ) : total = qs . count ( ) if total < min_batch_size : batch_size = total else : batch_size = int ( total / num_batches ) or total for start in range ( 0 , total , batch_size ) : end = min ( start + batch_size , total ) yield ( start , end , total , qs [ start : end ] )