Pagination for Tortoise-ORM on FastAPI
Project description
Usage
Supposing in myapp.schema
you have a pydantic BaseModel
to represent your model
from fastapi import Depends
from tortoise_pagination import Pagination, Page
from myapp.main import app
from myapp.models import MyModel
from myapp.schema import MySchema
@app.get('/mymodel')
async def my_view(pagination: Depends(Pagination.from_query)) -> Page[MySchema]:
return await pagination.paginated_response(MyModel.all(), MySchema)
now you can request with:
curl http://localhost:8000/mymodel?offset=0&limit=20
returned structure:
- items list[MySchema]
- count: NonNegativeInt -> the number of entries for this queryset
(
MyModel.all().count()
) wich the frontend will need to be able to display a pagination
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for tortoise_pagination-1.1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83521acfbb3c0314e67165e6324a8323584999196d388dd66ddc6a095cea4e9d |
|
MD5 | d30fbb1a615e9af983e33ee74f5d9cf1 |
|
BLAKE2b-256 | d6f38713b05f866bd666f05e10c8c2f209223d3bac82476ac0bab85e0fba5cdc |
Close
Hashes for tortoise_pagination-1.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0447d046acf4e7d9ba1973baea1d1cd9724e16dc7ce8e0f37fa6b2250eb6f00f |
|
MD5 | 47d3e330c14b15023a45f7c66dc8b87c |
|
BLAKE2b-256 | f3392af1776886118511759025e873b8cc16ca722ac5ed91bf6150dd5f0be87c |