Skip to content

Commit

Permalink
feat:update SQLModelFieldParser
Browse files Browse the repository at this point in the history
  • Loading branch information
amisadmin committed Feb 27, 2022
1 parent cb14d5e commit 940f149
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fastapi_amis_admin/crud/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from sqlalchemy import Column
from sqlalchemy.engine import Row
from sqlalchemy.orm import InstrumentedAttribute
from sqlalchemy.sql.elements import Label
from sqlmodel import SQLModel
from sqlmodel.main import SQLModelMetaclass
from sqlmodel.sql.expression import Select
Expand Down Expand Up @@ -49,13 +50,15 @@ def get_column(self, field: SQLModelField) -> Optional[Column]:
return self.default_model.__table__.columns.get(field)
return None

def get_alias(self, field: Union[Column, SQLModelField]) -> str:
def get_alias(self, field: Union[Column, SQLModelField, Label]) -> str:
if isinstance(field, Column):
return field.name if field.table.name == self.default_model.__tablename__ else self._alias_format.format(
table_name=field.table.name, field_key=field.name)
elif isinstance(field, InstrumentedAttribute):
return field.key if field.class_.__tablename__ == self.default_model.__tablename__ else self._alias_format.format(
table_name=field.class_.__tablename__, field_key=field.key)
elif isinstance(field, Label):
return field.key
elif isinstance(field, str) and field in self.default_model.__fields__:
return field
return ''
Expand Down

0 comments on commit 940f149

Please sign in to comment.