Conversation
…related objects to prefetch, search, etc
There was a problem hiding this comment.
Pull request overview
Extends the ModelAdmin.orm_get_list() API (and ORM-specific implementations) to accept extra parameters for prefetching related objects and augmenting search fields, enabling more flexible list queries across supported ORMs.
Changes:
- Add
prefetch_related_fieldsandadditional_search_fieldsparameters toorm_get_list()in the base admin and ORM backends (Tortoise, SQLAlchemy, PonyORM, Django). - Add ORM-specific test cases validating the new parameters (plus SQLAlchemy prefetch edge cases).
- Update generated documentation to reflect the new parameters and provide an example of forwarding them.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
fastadmin/models/base.py |
Extends the abstract orm_get_list() signature/docstring with the new parameters. |
fastadmin/models/orms/tortoise.py |
Adds prefetch support and merges search fields with additional_search_fields for Tortoise. |
fastadmin/models/orms/sqlalchemy.py |
Adds prefetch support (including nested paths) and merges search fields for SQLAlchemy. |
fastadmin/models/orms/ponyorm.py |
Adds prefetch support and merges search fields for PonyORM. |
fastadmin/models/orms/django.py |
Adds prefetch support and merges search fields for Django ORM. |
tests/models/test_orm.py |
Adds tests to cover new parameters across ORMs and SQLAlchemy prefetch edge cases. |
docs/build.py |
Adds documentation content describing how to forward the new parameters. |
docs/index.html |
Updates generated docs with the new signature and example; bumps “Updated” date. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if search and search_fields: | ||
| search_conditions = [Q(**{f + "__icontains": search}) for f in search_fields] | ||
| search_q = search_conditions[0] if len(search_conditions) == 1 else operator.or_(*search_conditions) | ||
| qs = qs.filter(search_q) |
There was a problem hiding this comment.
operator.or_ only accepts 2 arguments. When search_fields contains 3+ entries (now more likely with additional_search_fields), operator.or_(*search_conditions) will raise TypeError. Build the combined Q with functools.reduce(operator.or_, search_conditions) (or loop with q |= cond) instead.
…related objects to prefetch, search, etc
References
Summary
Are there any open tasks or blockers?