Skip to content

Commit

Permalink
Filters for remote columns will work through explicitly specified for…
Browse files Browse the repository at this point in the history
…eign key.
  • Loading branch information
mrjoes committed Apr 4, 2012
1 parent 6a9f631 commit 8679ea3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/sqla/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class PostAdmin(sqlamodel.ModelView):

searchable_columns = ('title', User.username)

column_filters = (User,
column_filters = ('user',
'title',
'date',
filters.FilterLike(Post.title, 'Fixed Title', options=(('test1', 'Test 1'), ('test2', 'Test 2'))))
Expand Down
7 changes: 4 additions & 3 deletions flask_adminex/ext/sqlamodel/view.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

from sqlalchemy.orm.attributes import InstrumentedAttribute
from sqlalchemy.orm import subqueryload
from sqlalchemy.sql.expression import desc
Expand Down Expand Up @@ -280,18 +281,18 @@ def scaffold_filters(self, name):
if attr is None:
raise Exception('Failed to find field for filter: %s' % name)

if hasattr(attr, '_sa_class_manager'):
if hasattr(attr, 'property') and hasattr(attr.property, 'direction'):
filters = []

for p in self._get_model_iterator(attr):
for p in self._get_model_iterator(attr.property.mapper.class_):
if hasattr(p, 'columns'):
# TODO: Check for multiple columns
column = p.columns[0]

if column.foreign_keys or column.primary_key:
continue

visible_name = '%s / %s' % (self.get_column_name(attr.__table__.name),
visible_name = '%s / %s' % (self.get_column_name(attr.prop.table.name),
self.get_column_name(p.key))

type_name = type(column.type).__name__
Expand Down

0 comments on commit 8679ea3

Please sign in to comment.