From 05bc5b1d08b12474dcb31823caafd156a948f3de Mon Sep 17 00:00:00 2001 From: Seva D Date: Mon, 13 Apr 2026 17:29:05 +0400 Subject: [PATCH 1/6] Add obj parameter for upload method --- docs/build.py | 7 +- docs/index.html | 85 +++++++++++++++++-- examples/django_djangoorm/orm/models.py | 3 + examples/fastapi_ponyorm/example.py | 2 + examples/fastapi_sqlalchemy/example.py | 2 + examples/fastapi_tortoiseorm/example.py | 12 +++ examples/flask_sqlalchemy/example.py | 10 +++ fastadmin/api/frameworks/django/app/api.py | 2 + fastadmin/api/frameworks/fastapi/api.py | 3 + fastadmin/api/frameworks/flask/api.py | 2 + fastadmin/api/service.py | 4 + fastadmin/models/base.py | 6 ++ fastadmin/static/index.min.js | 4 +- .../src/components/form-container/index.tsx | 2 +- .../src/components/upload-file/index.test.tsx | 17 ++++ frontend/src/components/upload-file/index.tsx | 4 +- .../components/upload-image/index.test.tsx | 15 ++++ .../src/components/upload-image/index.tsx | 4 +- pyproject.toml | 5 +- tests/api/frameworks/django/test_app.py | 2 + tests/api/test_service.py | 23 ++++- tests/models/test_base.py | 2 +- 22 files changed, 197 insertions(+), 19 deletions(-) diff --git a/docs/build.py b/docs/build.py index 875aa76..83599ba 100644 --- a/docs/build.py +++ b/docs/build.py @@ -44,6 +44,10 @@ def read_cls_docstring(cls): def get_versions(): return [ + { + "version": "0.4.9", + "changes": ["Add obj parameter to upload_file method."], + }, { "version": "0.4.8", "changes": [ @@ -426,7 +430,6 @@ def read_example(rel_path: str) -> str: def get_page_context(page_url): - from fastadmin import InlineModelAdmin, ModelAdmin, WidgetType, widget_action from fastadmin.models.base import BaseModelAdmin from fastadmin.models.schemas import ( @@ -759,7 +762,7 @@ async def save_model(self, id, payload): }, { "type": "text", - "content": "For file and image fields use UploadFile and UploadImage widgets in formfield_overrides. Implement upload_file(obj, field_name, file_name, file_content) on the model admin to handle uploads; it must return the file URL (e.g. after saving to disk or S3).", + "content": "For file and image fields use UploadFile and UploadImage widgets in formfield_overrides. Implement upload_file(field_name, file_name, file_content, obj=None) on the model admin to handle uploads; it must return the file URL (e.g. after saving to disk or S3).", }, { "type": "text", diff --git a/docs/index.html b/docs/index.html index 865e616..e9cc662 100644 --- a/docs/index.html +++ b/docs/index.html @@ -192,6 +192,10 @@

FastAdmin