Django QuerySet restriction

You can limit the results to a QuerySet by doing something like this:

qs = MyModel.objects.all()[:3] 

Since QuerySet is usually evaluated lazily, is it possible to remove this limit from qs before repeating it?

I was hoping for something direct, like qs = qs[:] or qs = qs[0:] , but it doesn't work. So far I can only work qs.query.clear_limits() , but I'm not sure if this is part of the public API (I had to wade through the Django source code to find it).

+5
source share
1 answer

According to Alasdair, it seems that the documented public API does not disclose the restrictions. Probably because it is not a very common thing.

In any case, since it is not documented anywhere, I consider it โ€œinternalโ€ and is subject to change without notice.

0
source

Source: https://habr.com/ru/post/1275117/


All Articles