Pages and rows
The following methods allow you to paginate and limit the number of rows in a query.
-
paginate(page: int) -> QuerySet -
limit(limit_count: int) -> QuerySet -
offset(offset: int) -> QuerySet -
get() -> Model
-
First () -> Model
-
query set proxy
QuerysetProxy.paginate(page: int)methodQuerysetProxy.limit(limit_count: int)methodQuerysetProxy.offset(offset: int)method
paging
paginate(page: int, page_size: int = 20) -> QuerySet
Combines offset and restriction methods based on page number and size
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
Note that paginate(2) is equivalent to offset(20).limit(20)
impose restrictions on
limit(limit_count: int, limit_raw_sql: bool = None) -> QuerySet
You can limit the results to the number of parent models you want.
To limit the actual number of database query rows rather than the number of main models, use the limit_raw_sql parameter flag and set it to True.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Note
So operations like filter(), select_related(), limit() and offset() etc. can be chained.
Something like Track.object.select_related("album").filter(album__name="Malibu").offset(1).limit(1).all()
counteract
offset(offset: int, limit_raw_sql: bool = None) -> QuerySet
You can also offset the results by the number of master models required.
To offset the actual number of database query rows rather than the number of main model rows, use the limit_raw_sql parameter flag and set it to True.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Note
So operations like filter(), select_related(), limit() and offset() etc. can be chained.
Something like Track.object.select_related("album").filter(album__name="Malibu").offset(1).limit(1).all()
get
get(**kwargs) -> Model
Get the first row from the database that satisfies the kwargs setting criteria.
If no condition is set, it returns the last row sorted by pk in db.(Filter/exclude also cannot be used to set conditions).
!!!tip To learn more about get, visit read/get
number one
First () -> Model
Gets the first row sorted in ascending order by primary key column from the database.
!!!tip To learn more about your first visit, read/first
QuerysetProxy method
Returns a list of related models when directly accessing the related ManyToMany field and ReverseForeignKey.
But it also exposes a subset of the QuerySet API, so you can filter, create, select related models, and so on directly from the parent model.
paging
Same pagination functionality as above, but allows you to paginate related objects from the other end of the relationship.
!!!tip To learn more about QuerysetProxy, visit the QuerysetProxy section
impose restrictions on
Identical to the limit function above, but allows you to paginate related objects from the other side of the relationship.
!!!tip To learn more about QuerysetProxy, visit the QuerysetProxy section
counteract
Identical to the offset function above, but allows you to paginate related objects from the other side of the relationship.
!!!tip To learn more about QuerysetProxy, visit the QuerysetProxy section