Commit 53fce33b authored by Paul Brown's avatar Paul Brown

Merge pull request #1214 from vToMy/feature_hybrid_property

Added hybrid properties filters support
parents 7f96a02b 3e074fba
......@@ -564,11 +564,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_):
......@@ -599,14 +596,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 properties
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),
......@@ -629,7 +631,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