
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
fastapi-tortoise-pagination
Advanced tools
这个是一个基于FastApi+tortoise-orm的查询集分页器
主要通过对QuerySet进行分页排序等进行操作,再对即将响应的数据进行序列化,相比较一些先序列化再分页的分页器,这个会更轻简快速。
一、介绍 该分页器主要分为三个块:Params、PagePydantic和pagination
total: int # 查询总数
page: int
size: int
total_pages: int # 总页数
next: str # 下页url
previous: str # 上页url
响应模型,即返回给前端的数据模型 2. pagination 分页操作,将查询集QuerySet进行分页或者排序等操作,然后在根据用户自定义的Pydantic进行序列化,最后返回分页后的数据
二、快速开始:
pip install fastapi-tortoise-pagination
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)
FAQs
A paginator based on fastapi and tortoise-orm
We found that fastapi-tortoise-pagination demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.