Commit 51ded02d authored by Tom Kedem's avatar Tom Kedem

- fixed hybrid properties support

- added hybrid properties filters support
parent 97cc3252
......@@ -484,7 +484,7 @@ class ModelView(BaseModelView):
"Failed on: {0}".format(c))
else:
# column is in same table, use only model attribute name
column_name = column.key
column_name = column.key if hasattr(column, 'key') and column.key else text_type(c)
# column_name must match column_name used in `get_list_columns`
result[column_name] = column
......@@ -517,7 +517,7 @@ class ModelView(BaseModelView):
column_name = text_type(c)
else:
# column is in same table, use only model attribute name
column_name = column.key
column_name = column.key if hasattr(column, 'key') and column.key else text_type(c)
visible_name = self.get_column_name(column_name)
......@@ -558,11 +558,8 @@ class ModelView(BaseModelView):
if attr is None:
raise Exception('Failed to find field for filter: %s' % name)
# Figure out filters for related column, unless it's a hybrid_property
if isinstance(attr, ColumnElement):
warnings.warn(('Unable to scaffold the filter for %s, scaffolding '
'for hybrid_property is not supported yet.') % name)
elif hasattr(attr, 'property') and hasattr(attr.property, 'direction'):
# Figure out filters for related column
if hasattr(attr, 'property') and hasattr(attr.property, 'direction'):
filters = []
for p in self._get_model_iterator(attr.property.mapper.class_):
......@@ -593,14 +590,19 @@ class ModelView(BaseModelView):
return filters
else:
columns = tools.get_columns_for_field(attr)
is_hybrid_property = isinstance(attr, ColumnElement)
if is_hybrid_property:
column = attr
else:
columns = tools.get_columns_for_field(attr)
if len(columns) > 1:
raise Exception('Can not filter more than on one column for %s' % name)
if len(columns) > 1:
raise Exception('Can not filter more than on one column for %s' % name)
column = columns[0]
column = columns[0]
if (tools.need_join(self.model, column.table) and
# Join not needed for hybrid attributes
if (not is_hybrid_property and tools.need_join(self.model, column.table) and
name not in self.column_labels):
visible_name = '%s / %s' % (
self.get_column_name(column.table.name),
......@@ -623,7 +625,7 @@ class ModelView(BaseModelView):
if joins:
self._filter_joins[column] = joins
elif tools.need_join(self.model, column.table):
elif not is_hybrid_property and tools.need_join(self.model, column.table):
self._filter_joins[column] = [column.table]
return flt
......
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