Skip to main content

A paginator based on fastapi and tortoise-orm

Reason this release was yanked:

link failed

Project description

这个是一个基于FastApi+tortoise-orm的查询集分页器

主要通过对QuerySet进行分页排序等进行操作,再对即将响应的数据进行序列化,相比较一些先序列化再分页的分页器,这个会更轻简快速。

一、介绍 该分页器主要分为三个块:Params、PagePydantic和pagination

  1. Params 前端传的参数,包括page(页数)、size(页面大小)和order_by(排序字段,选传)
  2. PagePydantic
    total: int          # 查询总数
    page: int
    size: int
    total_pages: int    # 总页数
    next: str           # 下页url
    previous: str       # 上页url

响应模型,即返回给前端的数据模型 2. pagination 分页操作,将查询集QuerySet进行分页或者排序等操作,然后在根据用户自定义的Pydantic进行序列化,最后返回分页后的数据

二、快速开始:

  1. install(安装)
    pip install fastapi_tortoise_pagination
    
  2. 使用
    class ForumArticle(models.Model):
        """论坛文章"""
        id = fields.IntField(pk=True)
        user = fields.ForeignKeyField("cp_model.User", on_delete=fields.CASCADE)
        title = fields.CharField(max_length=32, default='', null=True)  # 文章标题
        content = fields.TextField(default='', null=True, blank=True)  # 文章正文

    class ForumArticleSchema(
    pydantic_model_creator(ForumArticle,
                           name="ForumArticleSchema",
                           exclude=())
    ):
    pass


    class TestViewSet(BaseViewSet):
        model = ForumArticle
        schema = ForumArticleSchema
        pk_type = str
        views = {
        }

    @Action.get("/list",  response_model=PagePydantic[ForumArticleSchema],description="分页获取帖子列表")  #
    async def list(self, params: Params = Depends()):
        query_set = ForumArticle.filter(is_delete=0)
        return await pagination(pydantic_model=ForumArticleSchema, query_set=query_set, params=params)

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

fastapi-tortoise-pagination-0.1.2.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file fastapi-tortoise-pagination-0.1.2.tar.gz.

File metadata

File hashes

Hashes for fastapi-tortoise-pagination-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0111d9a536f50aaf0251709822f41c3b4241ecde5f2e0f0f09196cb9adc079fb
MD5 3a88b347eb85f04edd6995bbbf161166
BLAKE2b-256 5805c08a92deda9a56e450d9b083a4db416da3c370ca25e5d4d78530d5eab114

See more details on using hashes here.

File details

Details for the file fastapi_tortoise_pagination-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_tortoise_pagination-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b3a2bbf2e80846297a7dab10ed8ec4cfb991c487755c3c14915789f8022b679a
MD5 7f254c4e781535448599839b6b52f8b3
BLAKE2b-256 40c35df5c574596823cc7908277ccfa7f75c5c71263efffea83422f161e97691

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page