-
I'm trying to use starlette-admin in my FastAPI project. Can someone guide me with tips on how to do it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can create your custom ImageField and override the @dataclass
class MyImageField(BaseImageField):
async def serialize_value(
self, request: Request, value: Any, action: RequestAction
) -> dict:
return {"url": request.url_for...} then using it your view class MyModelView(ModelView):
fields = [... , MyImageField("avatar"), ... ]
Example: https://github.com/jowilf/starlette-admin/blob/main/starlette_admin/contrib/sqla/fields.py#L57 |
Beta Was this translation helpful? Give feedback.
You can create your custom ImageField and override the
serialize_value
method. You only need to return a dictionary withfilename
,content-type
, andurl
.then using it your view
Example: https://github.com/jowilf/starlette-admin/blob/main/starlette_admin/contrib/sqla/fields.py#L57