We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe the bug
class DeptModel(Model): name = fields.CharField(max_length=50, description='部门名称') sort = fields.SmallIntField(default=0, description='排序') leader = fields.CharField(max_length=30, default=None, null=True, description='负责人') phone = fields.CharField(max_length=30, default=None, null=True, description='手机') email = fields.CharField(max_length=50, default=None, null=True, description='邮箱') status = fields.BooleanField(default=True, description='部门状态') parent: fields.ForeignKeyNullableRelation['DeptModel'] = fields.ForeignKeyField( 'models.DeptModel', null=True, related_name='children', description='父级部门', on_delete=fields.CASCADE, ) children: fields.ReverseRelation['DeptModel'] class Meta: table = 'sys_dept' table_description = '部门' ordering = ['parent_id', '-sort'] DeptOut = pydantic_model_creator( DeptModel, name='DeptOut', allow_cycles=True, model_config=modelOutConfig, ) @router.get('/{pk}', summary='获取部门信息') async def info(pk: Annotated[int, Path(...)]): dept = await DeptOut.from_tortoise_orm(await DeptModel.get_or_none(id=pk)) return dept.model_dump()
{ "id": 13, "name": "部门2", "sort": 0, "leader": null, "phone": null, "email": null, "status": true }
Why hasn't the parent_id been returned??
parent_id
The text was updated successfully, but these errors were encountered:
@elkon028 have you initialized tortoise models? You might need to do early model init BEFORE you create Pydantic schemas.
Sorry, something went wrong.
No branches or pull requests
Describe the bug
returned
Why hasn't the
parent_id
been returned??The text was updated successfully, but these errors were encountered: