Commit 3c4406cf authored by Serge S. Koval's avatar Serge S. Koval Committed by GitHub

Merge pull request #1352 from vToMy/bugfix/remote_hybrid_property

Support association proxies in path when determining hybrid property
parents 155f508e 8ccc81f6
from sqlalchemy import tuple_, or_, and_, inspect from sqlalchemy import tuple_, or_, and_, inspect
from sqlalchemy.ext.declarative.clsregistry import _class_resolver
from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.ext.associationproxy import ASSOCIATION_PROXY from sqlalchemy.ext.associationproxy import ASSOCIATION_PROXY
from sqlalchemy.sql.operators import eq from sqlalchemy.sql.operators import eq
...@@ -190,12 +191,20 @@ def get_hybrid_properties(model): ...@@ -190,12 +191,20 @@ def get_hybrid_properties(model):
def is_hybrid_property(model, attr_name): def is_hybrid_property(model, attr_name):
names = attr_name.split('.') if isinstance(attr_name, string_types):
last_model = model names = attr_name.split('.')
for i in range(len(names)-1): last_model = model
last_model = getattr(last_model, names[i]).property.argument for i in range(len(names)-1):
last_name = names[-1] attr = getattr(last_model, names[i])
return last_name in get_hybrid_properties(last_model) if is_association_proxy(attr):
attr = attr.remote_attr
last_model = attr.property.argument
if isinstance(last_model, _class_resolver):
last_model = model._decl_class_registry[last_model.arg]
last_name = names[-1]
return last_name in get_hybrid_properties(last_model)
else:
return attr_name.name in get_hybrid_properties(model)
def is_relationship(attr): def is_relationship(attr):
......
...@@ -618,7 +618,8 @@ class ModelView(BaseModelView): ...@@ -618,7 +618,8 @@ class ModelView(BaseModelView):
is_hybrid_property = tools.is_hybrid_property(self.model, name) is_hybrid_property = tools.is_hybrid_property(self.model, name)
if is_hybrid_property: if is_hybrid_property:
column = attr column = attr
column.key = name.split('.')[-1] if isinstance(name, string_types):
column.key = name.split('.')[-1]
else: else:
columns = tools.get_columns_for_field(attr) columns = tools.get_columns_for_field(attr)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment