Skip to content

Commit

Permalink
Add custom relationship statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Максим committed Aug 15, 2024
1 parent 7eda592 commit eb7deba
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion sqladmin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ def _inner(func: T_CC) -> T_CC:


class ModelConverterBase:
relationships_statements: dict[str, str] = {}
"""
Select statement for relationships.
"""

_converters: dict[str, ConverterCallable] = {}

def __init__(self) -> None:
Expand Down Expand Up @@ -229,7 +234,10 @@ async def _prepare_select_options(
session_maker: sessionmaker,
) -> list[tuple[str, Any]]:
target_model = prop.mapper.class_
stmt = select(target_model)
if prop.key in self.relationships_statements:
stmt = self.relationships_statements[prop.key]
else:
stmt = select(target_model)

if is_async_session_maker(session_maker):
async with session_maker() as session:
Expand Down

0 comments on commit eb7deba

Please sign in to comment.