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
6e8226a4
Commit
6e8226a4
authored
Jan 03, 2013
by
Artem Serga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#4 - Fix filters, presented as string
parent
68b681cf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
11 deletions
+26
-11
view.py
flask_admin/contrib/sqlamodel/view.py
+26
-11
No files found.
flask_admin/contrib/sqlamodel/view.py
View file @
6e8226a4
...
...
@@ -394,8 +394,20 @@ class ModelView(BaseModelView):
"""
Return list of enabled filters
"""
join_tables
=
[]
if
isinstance
(
name
,
basestring
):
attr
=
getattr
(
self
.
model
,
name
,
None
)
model
=
self
.
model
for
attribute
in
name
.
split
(
'.'
):
value
=
getattr
(
model
,
attribute
)
if
(
hasattr
(
value
,
'property'
)
and
hasattr
(
value
.
property
,
'direction'
)
):
model
=
value
.
property
.
mapper
.
class_
table
=
model
.
__table__
if
self
.
_need_join
(
table
):
join_tables
.
append
(
table
)
attr
=
value
else
:
attr
=
name
...
...
@@ -423,9 +435,11 @@ class ModelView(BaseModelView):
visible_name
)
if
flt
:
if
self
.
_need_join
(
column
.
table
):
self
.
_filter_joins
[
column
.
table
.
name
]
=
column
.
table
table
=
column
.
table
if
join_tables
:
self
.
_filter_joins
[
table
.
name
.
name
]
=
join_tables
elif
self
.
_need_join
(
table
.
name
):
self
.
_filter_joins
[
table
.
name
.
name
]
=
[
table
.
name
]
filters
.
extend
(
flt
)
return
filters
...
...
@@ -449,9 +463,10 @@ class ModelView(BaseModelView):
if
flt
:
# If there's relation to other table, do it
if
self
.
_need_join
(
column
.
table
):
self
.
_filter_joins
[
column
.
table
.
name
]
=
column
.
table
if
join_tables
:
self
.
_filter_joins
[
column
.
table
.
name
]
=
join_tables
elif
self
.
_need_join
(
column
.
table
):
self
.
_filter_joins
[
column
.
table
.
name
]
=
[
column
.
table
]
return
flt
def
is_valid_filter
(
self
,
filter
):
...
...
@@ -581,10 +596,10 @@ class ModelView(BaseModelView):
# Figure out join
tbl
=
flt
.
column
.
table
.
name
join
=
self
.
_filter_joins
.
get
(
tbl
)
if
join
is
not
None
:
query
=
query
.
join
(
join
)
joins
.
add
(
t
bl
)
join
_tables
=
self
.
_filter_joins
.
get
(
tbl
,
[]
)
for
table
in
join_tables
:
query
=
query
.
join
(
table
)
joins
.
add
(
t
able
)
# Apply filter
query
=
flt
.
apply
(
query
,
value
)
...
...
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