Django models 使用mysql的limit和offset功能

參考:
Specifying limit and offset in Django QuerySet wont work-StackOverflow
django官方文檔django

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.ui

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

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

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

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

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

相關文章
相關標籤/搜索