编程知识 cdmana.com

Django models uses the limit and offset functions of MySQL

Reference resources :
Specifying limit and offset in Django QuerySet wont work-StackOverflow
django Official documents

Use a subset of Python’s array-slicing syntax to limit your QuerySet to a certain number of results. This is the equivalent of SQL’s LIMIT and OFFSET clauses.

For example, this returns the first 5 objects (LIMIT 5):

Entry.objects.all()[:5]

This returns the sixth through tenth objects (OFFSET 5 LIMIT 5):

Entry.objects.all()[5:10]

Negative indexing (i.e. Entry.objects.all()[-1]) is not supported.

版权声明
本文为[zhfang]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224104311398u.html

Scroll to Top