How do you split a Django queryset without evaluating it?

bmjrowe

I am dealing with a Queryset of over 5 million + items (For batch ML purposes) and I need to split the queryset (so I can perform multithreading operations) without evaluating the queryset as I only ever need to access each item in the queryset once and thus I don't want to cache the queryset items which evaluating causes.

Is it possible to select the items into one queryset and split this without evaluating? or am I going to have to approach it by querying for multiple querysets using Limits [:size] to achieve this behaviour?

N.B: I am aware that an Iterable can be used to cycle through a queryset without evaluating it but my question is related to how I can I split a queryset (if possible) to then run an iterable on each of the splitted querysets.

DhiaTN

Django provides a few classes that help you manage paginated data – that is, data that’s split across several pages, with “Previous/Next” links:

from django.core.paginator import Paginator

object_list = MyModel.objects.all()
paginator = Paginator(object_list, 10) # Show 10 objects per page, you can choose any other value

for i in paginator.page_range(): # A 1-based range iterator of page numbers, e.g. yielding [1, 2, 3, 4].
    data = iter(paginator.get_page(i))
    # use data

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do you combine two querysets into one queryset(not a list) in django?

How do you selectively simplify arguments to each time a function is called, without evaluating the function itself?

How to split a string in django QuerySet object

How do you extract unique queryset from queryset of objects with ManyToManyField

How do you override a ModelViewSet's get_queryset in Django Rest Framework 3?

Django: How do you compare a QuerySet with fields on a ForeignKey object's property?

Can you do additional math on an aggregate value in a Django queryset

How to do this Group By Query in Django QuerySet?

how do I refer to a QuerySet element in Django?

Run QuerySet Django without for

How do I store a boolean test/expression without Evaluating it?

How do I dump yaml without evaluating anchor values?

How do you format a queryset before returning to admin site for showing?

How do you split a string inside a list?

How do you split a string at a specific point?

How do you split string at current position?

How do you split a String into a [String] and not [Substring]?

How do you open vimwiki in a new split?

How do you split a string into individual characters?

How do you split at the end of the line in Java?

How to Get a Distinct Filtered QuerySet In Django Without Using the distinct Method?

Django: How to count a queryset and return a slice without hitting DB twice?

Django : how to use modified queryset in templates without saving modification

How to search a queryset by id without additional db calls in Django

How to delete from queryset without deleting the original model itself in Django

How do I do a not equal in Django queryset filtering?

How do you split a text file using the split method in NodeJS?

How can you split a string in R without removing the characters you want to split after?

how to subquery in queryset in django?