Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
53fce33b
Commit
53fce33b
authored
Mar 28, 2016
by
Paul Brown
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1214 from vToMy/feature_hybrid_property
Added hybrid properties filters support
parents
7f96a02b
3e074fba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
11 deletions
+13
-11
view.py
flask_admin/contrib/sqla/view.py
+13
-11
No files found.
flask_admin/contrib/sqla/view.py
View file @
53fce33b
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment