Этот контент переведён с помощью машинной генерации, направляемой
составленными людьми глоссариями и руководствами по стилю. Поскольку
текст не проверяется вручную построчно, возможны отдельные ошибки или
неестественные формулировки.
В случае любых расхождений авторитетным источником считается
оригинальная версия на английском языке.
Полный справочник атрибутов и методов backend'а SQLModel (starlette_admin.contrib.sqlmodel),
сгенерированный из docstring. В основе SQLModel лежит SQLAlchemy, поэтому Admin и ModelView — это
тонкие подклассы SQLAlchemy backend'а, которые валидируют данные форм через
Pydantic-слой модели. Пошаговое практическое руководство см. в разделе
Интеграция SQLModel.
classModelView(BaseModelView):def__init__(self,model:type[SQLModel],icon:str|None=None,display_name:str|None=None,menu_label:str|None=None,key:str|None=None,converter:BaseSQLAModelConverter|None=None,):super().__init__(model,icon,display_name,menu_label,key,converter)asyncdefvalidate(self,request:Request,data:dict[str,Any])->None:"""Validate form data against the SQLModel, excluding file and relation fields. File and relation fields hold values (uploads, related objects) that the Pydantic model itself cannot validate, so they are stripped from `data` before calling `model_validate`. """fields=self.get_fields_list(request)fields_to_exclude=[f.nameforfinfieldsifisinstance(f,(FileField,RelationField))]payload={k:vfork,vindata.items()ifknotinfields_to_exclude}payload.update(_fk_values_from_relations(self.model,fields,data))self.model.model_validate(payload)asyncdefhandle_exception(self,request:Request,exc:Exception)->None:ifisinstance(exc,ValidationError):key_map=_fk_columns_by_relation(self.model,self.get_fields_list(request))raisepydantic_error_to_form_validation_errors(exc,key_map)returnawaitsuper().handle_exception(request,exc)# pragma: no cover
validate(request,data)async
Validate form data against the SQLModel, excluding file and relation fields.
File and relation fields hold values (uploads, related objects) that the
Pydantic model itself cannot validate, so they are stripped from data
before calling model_validate.
Source code in starlette_admin/contrib/sqlmodel/view.py
asyncdefvalidate(self,request:Request,data:dict[str,Any])->None:"""Validate form data against the SQLModel, excluding file and relation fields. File and relation fields hold values (uploads, related objects) that the Pydantic model itself cannot validate, so they are stripped from `data` before calling `model_validate`. """fields=self.get_fields_list(request)fields_to_exclude=[f.nameforfinfieldsifisinstance(f,(FileField,RelationField))]payload={k:vfork,vindata.items()ifknotinfields_to_exclude}payload.update(_fk_values_from_relations(self.model,fields,data))self.model.model_validate(payload)
Inline editing of SQLModel-backed related records inside a parent form.
Inherits FK detection and session logic from the SQLAlchemy
InlineModelView and adds SQLModel Pydantic validation on top.
Declare model as a class attribute (a SQLModel table class). fk_attr
is optional and is auto-detected from the parent's SQLAlchemy relationship
when omitted.
Example:
```python
class CommentInline(InlineModelView):
model = Comment
fields = ["id", "author", "body"]
extra = 1
class PostView(ModelView):
inlines = [CommentInline]
```
Source code in starlette_admin/contrib/sqlmodel/view.py
classInlineModelView(SQLAInlineModelView):"""Inline editing of SQLModel-backed related records inside a parent form. Inherits FK detection and session logic from the SQLAlchemy `InlineModelView` and adds SQLModel Pydantic validation on top. Declare `model` as a class attribute (a `SQLModel` table class). `fk_attr` is optional and is auto-detected from the parent's SQLAlchemy relationship when omitted. Example: ```python class CommentInline(InlineModelView): model = Comment fields = ["id", "author", "body"] extra = 1 class PostView(ModelView): inlines = [CommentInline] ``` """model:ClassVar[type[SQLModel]]# type: ignore[misc]asyncdefvalidate(self,request:Request,data:dict[str,Any])->None:fields=self.get_fields_list(request)fields_to_exclude=[f.nameforfinfieldsifisinstance(f,(FileField,RelationField))]payload={k:vfork,vindata.items()ifknotinfields_to_exclude}payload.update(_fk_values_from_relations(self.model,fields,data))self.model.model_validate(payload)asyncdefhandle_exception(self,request:Request,exc:Exception)->None:ifisinstance(exc,ValidationError):key_map=_fk_columns_by_relation(self.model,self.get_fields_list(request))raisepydantic_error_to_form_validation_errors(exc,key_map)returnawaitsuper().handle_exception(request,exc)# pragma: no cover