Skip to content

Allow TortoiseMixin.orm_get_list() to take additional parameters for related objects to prefetch, search, etc#124

Merged
vsdudakov merged 2 commits intomainfrom
enhancement/enhance_orm_get_list
Feb 23, 2026
Merged

Allow TortoiseMixin.orm_get_list() to take additional parameters for related objects to prefetch, search, etc#124
vsdudakov merged 2 commits intomainfrom
enhancement/enhance_orm_get_list

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

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_fields and additional_search_fields parameters to orm_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.

Comment on lines +277 to 280
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)
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@vsdudakov vsdudakov enabled auto-merge (squash) February 23, 2026 19:46
@vsdudakov vsdudakov disabled auto-merge February 23, 2026 19:46
@vsdudakov vsdudakov merged commit 27478ad into main Feb 23, 2026
@vsdudakov vsdudakov deleted the enhancement/enhance_orm_get_list branch February 23, 2026 19:46
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