Slice on Django Model Queryset -
i try run query paged results, model.objects.all()[start: start+page_size]
.
i want know whether there more pages load, say, want know whether start+page_size < model.objects.all().count().
my question is, if call all()
twice here, whether django executes same query twice (one slice operation[]
, 1 count()
).
another question if slice on model.objects.all()
model.objects.all()[2:9]
whether django fetch data db , slice python, or django fetch sql limit limit 2 9
yes, makes 2 queries, these not "same query" @ all. 1 select * mymodel limit <page_size> offset <start>
, other select count(*) mymodel
.
if want avoid 2 queries, simple fix ask 1 more record need:
model.objects.all()[start: start+page_size+1]
then can iterate page_size, , show next button if record there.
Comments
Post a Comment