mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2025-04-25 08:13:40 +03:00
9 lines
239 B
Python
9 lines
239 B
Python
from django.db.models import QuerySet
|
|
|
|
|
|
def batch_qs(qs: QuerySet, batch_size: int = 1000):
|
|
total = qs.count()
|
|
for start in range(0, total, batch_size):
|
|
end = min(start + batch_size, total)
|
|
yield from qs[start:end]
|