Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the file-upload flow so upload_file(...) handlers can optionally receive the current ORM object instance (obj) when uploading from a change/edit page (via an id query parameter), while keeping add/create-page uploads as obj=None.
Changes:
- Add
objparameter toBaseModelAdmin.upload_file(...)and pass it fromApiService.upload_file(...). - Extend FastAPI/Flask/Django upload endpoints and frontend upload widgets to forward an optional
id(query param). - Update tests, examples, docs, and bump version to
0.4.9.
Reviewed changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
fastadmin/models/base.py |
Adds obj parameter to the upload_file admin hook signature. |
fastadmin/api/service.py |
Loads an object by id and passes obj into the upload handler. |
fastadmin/api/frameworks/fastapi/api.py |
Adds optional id query param to upload endpoint. |
fastadmin/api/frameworks/flask/api.py |
Reads optional id from query string and forwards to service. |
fastadmin/api/frameworks/django/app/api.py |
Reads optional id from query string and forwards to service. |
frontend/src/components/upload-file/index.tsx |
Appends optional ?id= to the upload action URL. |
frontend/src/components/upload-image/index.tsx |
Appends optional ?id= to the upload action URL. |
frontend/src/components/form-container/index.tsx |
Passes form id down to upload widgets. |
tests/api/test_service.py |
Adds coverage for upload with/without id, verifying obj propagation. |
tests/models/test_base.py |
Updates base admin abstract-method test for new signature. |
tests/api/frameworks/django/test_app.py |
Adjusts Django request mock to include GET and id=None expectation. |
examples/* |
Updates example upload_file signatures/docs to include obj. |
docs/index.html |
Updates docs to v0.4.9 and documents the new obj param. |
docs/build.py |
Adds v0.4.9 changelog entry + updates upload_file signature mention. |
pyproject.toml |
Bumps version to 0.4.9 and adds basedpyright config. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…udakov/fastadmin into feature/add_obj_parameter_for_upload
There was a problem hiding this comment.
Pull request overview
This PR extends FastAdmin’s upload pipeline so the backend upload handler can receive the current ORM object (when uploading from a change/edit page), and adds a separate “display URL” mechanism (get_file_url → {field}__url → valueRepr) so upload widgets can show presigned/CDN URLs while preserving the stored value.
Changes:
- Add
objparameter toBaseModelAdmin.upload_file()and plumb optionalidthrough the API layer to resolve/persist context for uploads. - Add
BaseModelAdmin.get_file_url()and emit{field_name}__urlduring serialization for upload fields; wire frontend widgets to consumevalueRepr. - Update docs/examples/tests/versioning/CI to reflect the new API and behavior.
Reviewed changes
Copilot reviewed 22 out of 23 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/models/test_base.py | Updates base contract test for upload_file(..., obj=None) and adds tests for get_file_url + {field}__url emission. |
| tests/api/test_service.py | Splits upload tests to cover both add (no id) and change (with id → obj resolved) flows. |
| tests/api/frameworks/django/test_app.py | Ensures Django request mock has GET and passes id=None for upload route. |
| pyproject.toml | Bumps package version to 0.4.9 and adds a basedpyright config block. |
| frontend/src/components/upload-image/index.tsx | Adds optional id and valueRepr; appends id to upload URL; uses valueRepr for display URL. |
| frontend/src/components/upload-image/index.test.tsx | Adds tests for valueRepr display and id query param behavior. |
| frontend/src/components/upload-file/index.tsx | Adds optional id and valueRepr; appends id to upload URL; uses valueRepr for display URL. |
| frontend/src/components/upload-file/index.test.tsx | Adds tests for valueRepr display and id query param behavior; updates Upload mock. |
| frontend/src/components/form-container/index.tsx | Passes id and {field}__url (valueRepr) into upload widgets on forms. |
| fastadmin/models/base.py | Adds get_file_url(), emits {field}__url for upload fields, and adds obj param to upload_file(). |
| fastadmin/api/service.py | Accepts optional id, resolves obj via orm_get_obj, and passes obj into upload_file(). |
| fastadmin/api/frameworks/flask/api.py | Reads optional id from querystring and forwards it to ApiService.upload_file. |
| fastadmin/api/frameworks/fastapi/api.py | Adds optional id query param and forwards it to ApiService.upload_file. |
| fastadmin/api/frameworks/django/app/api.py | Reads optional id from querystring and forwards it to ApiService.upload_file. |
| examples/flask_sqlalchemy/example.py | Updates example upload handler signature/docs to include obj. |
| examples/fastapi_tortoiseorm/example.py | Updates example upload handler signatures/docs to include obj. |
| examples/fastapi_sqlalchemy/example.py | Updates example upload handler signature/docs to include obj. |
| examples/fastapi_ponyorm/example.py | Updates example upload handler signature/docs to include obj. |
| examples/django_djangoorm/orm/models.py | Updates example upload handler signature/docs to include obj. |
| docs/index.html | Updates version/date/changelog and documents new upload_file(..., obj=None) + get_file_url behavior. |
| docs/build.py | Adds 0.4.9 changelog entries and updates rendered docs content for upload/get_file_url. |
| .github/workflows/ci.yml | Adjusts CI triggers, concurrency, formatting, and permissions; keeps backend/frontend test + build + codecov. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
References
Summary
Are there any open tasks or blockers?