Skip to content

Add obj parameter for upload method#130

Merged
vsdudakov merged 8 commits intomainfrom
feature/add_obj_parameter_for_upload
Apr 15, 2026
Merged

Add obj parameter for upload method#130
vsdudakov merged 8 commits intomainfrom
feature/add_obj_parameter_for_upload

Conversation

@vsdudakov
Copy link
Copy Markdown
Owner

References

Summary

Are there any open tasks or blockers?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 obj parameter to BaseModelAdmin.upload_file(...) and pass it from ApiService.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.

Comment thread frontend/src/components/upload-file/index.tsx Outdated
Comment thread frontend/src/components/upload-image/index.tsx Outdated
Comment thread fastadmin/api/service.py
Comment thread fastadmin/api/service.py
Comment thread fastadmin/api/frameworks/fastapi/api.py
Comment thread pyproject.toml
Comment thread fastadmin/models/base.py
vsdudakov and others added 3 commits April 13, 2026 17:43
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…udakov/fastadmin into feature/add_obj_parameter_for_upload
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}__urlvalueRepr) so upload widgets can show presigned/CDN URLs while preserving the stored value.

Changes:

  • Add obj parameter to BaseModelAdmin.upload_file() and plumb optional id through the API layer to resolve/persist context for uploads.
  • Add BaseModelAdmin.get_file_url() and emit {field_name}__url during serialization for upload fields; wire frontend widgets to consume valueRepr.
  • 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.

Comment thread fastadmin/api/service.py
Comment thread fastadmin/models/base.py
Comment thread frontend/src/components/upload-file/index.tsx Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…udakov/fastadmin into feature/add_obj_parameter_for_upload
@vsdudakov vsdudakov merged commit 668adf9 into main Apr 15, 2026
1 check passed
@vsdudakov vsdudakov deleted the feature/add_obj_parameter_for_upload branch April 15, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants