self.max_obj_num = max_obj_num

def _setup(self):
    for i in range(0, self._base_queryset.count(), self.max_obj_num):
        smaller_queryset = copy.deepcopy(self._base_queryset)[i:i + self.
            max_obj_num]
logger.debug('Grabbing next %s objects from DB' % self.max_obj_num)
for obj in smaller_queryset.iterator():
    yield obj

def __iter__(self):
    return self

def next(self):
    return self._generator.__next__()
Limiting Memory Use in a *Large* Django QuerySet