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
12995505
Commit
12995505
authored
Aug 04, 2013
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved SQLAlchemy overridden field support
parent
d1f58a58
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
15 deletions
+18
-15
simple.py
examples/sqla/simple.py
+1
-1
form.py
flask_admin/contrib/sqla/form.py
+16
-13
upload.py
flask_admin/form/upload.py
+1
-1
No files found.
examples/sqla/simple.py
View file @
12995505
...
@@ -46,7 +46,7 @@ class Post(db.Model):
...
@@ -46,7 +46,7 @@ class Post(db.Model):
date
=
db
.
Column
(
db
.
DateTime
)
date
=
db
.
Column
(
db
.
DateTime
)
user_id
=
db
.
Column
(
db
.
Integer
(),
db
.
ForeignKey
(
User
.
id
))
user_id
=
db
.
Column
(
db
.
Integer
(),
db
.
ForeignKey
(
User
.
id
))
user
=
db
.
relationship
(
User
,
backref
=
'posts'
)
user
=
db
.
relationship
(
User
,
backref
=
db
.
backref
(
'posts'
,
collection_class
=
set
)
)
tags
=
db
.
relationship
(
'Tag'
,
secondary
=
post_tags_table
)
tags
=
db
.
relationship
(
'Tag'
,
secondary
=
post_tags_table
)
...
...
flask_admin/contrib/sqla/form.py
View file @
12995505
...
@@ -87,32 +87,35 @@ class AdminModelConverter(ModelConverterBase):
...
@@ -87,32 +87,35 @@ class AdminModelConverter(ModelConverterBase):
elif
prop
.
direction
.
name
!=
'MANYTOMANY'
:
elif
prop
.
direction
.
name
!=
'MANYTOMANY'
:
kwargs
[
'validators'
]
.
append
(
validators
.
InputRequired
())
kwargs
[
'validators'
]
.
append
(
validators
.
InputRequired
())
# Override field type if necessary
override
=
self
.
_get_field_override
(
prop
.
key
)
if
override
:
return
override
(
**
kwargs
)
# Contribute model-related parameters
# Contribute model-related parameters
if
'allow_blank'
not
in
kwargs
:
if
'allow_blank'
not
in
kwargs
:
kwargs
[
'allow_blank'
]
=
local_column
.
nullable
kwargs
[
'allow_blank'
]
=
local_column
.
nullable
if
'query_factory'
not
in
kwargs
:
if
'query_factory'
not
in
kwargs
:
kwargs
[
'query_factory'
]
=
lambda
:
self
.
session
.
query
(
remote_model
)
kwargs
[
'query_factory'
]
=
lambda
:
self
.
session
.
query
(
remote_model
)
if
'widget'
not
in
kwargs
:
if
prop
.
direction
.
name
==
'MANYTOONE'
:
kwargs
[
'widget'
]
=
form
.
Select2Widget
()
elif
prop
.
direction
.
name
==
'ONETOMANY'
:
kwargs
[
'widget'
]
=
form
.
Select2Widget
(
multiple
=
True
)
elif
prop
.
direction
.
name
==
'MANYTOMANY'
:
kwargs
[
'widget'
]
=
form
.
Select2Widget
(
multiple
=
True
)
# Override field type if necessary
override
=
self
.
_get_field_override
(
prop
.
key
)
if
override
:
return
override
(
**
kwargs
)
if
prop
.
direction
.
name
==
'MANYTOONE'
:
if
prop
.
direction
.
name
==
'MANYTOONE'
:
return
QuerySelectField
(
widget
=
form
.
Select2Widget
(),
return
QuerySelectField
(
**
kwargs
)
**
kwargs
)
elif
prop
.
direction
.
name
==
'ONETOMANY'
:
elif
prop
.
direction
.
name
==
'ONETOMANY'
:
# Skip backrefs
# Skip backrefs
if
not
local_column
.
foreign_keys
and
getattr
(
self
.
view
,
'column_hide_backrefs'
,
False
):
if
not
local_column
.
foreign_keys
and
getattr
(
self
.
view
,
'column_hide_backrefs'
,
False
):
return
None
return
None
return
QuerySelectMultipleField
(
return
QuerySelectMultipleField
(
**
kwargs
)
widget
=
form
.
Select2Widget
(
multiple
=
True
),
**
kwargs
)
elif
prop
.
direction
.
name
==
'MANYTOMANY'
:
elif
prop
.
direction
.
name
==
'MANYTOMANY'
:
return
QuerySelectMultipleField
(
return
QuerySelectMultipleField
(
**
kwargs
)
widget
=
form
.
Select2Widget
(
multiple
=
True
),
**
kwargs
)
else
:
else
:
# Ignore pk/fk
# Ignore pk/fk
if
hasattr
(
prop
,
'columns'
):
if
hasattr
(
prop
,
'columns'
):
...
...
flask_admin/form/upload.py
View file @
12995505
...
@@ -68,7 +68,7 @@ class ImageUploadInput(object):
...
@@ -68,7 +68,7 @@ class ImageUploadInput(object):
"""
"""
empty_template
=
(
'<input
%(file)
s>'
)
empty_template
=
(
'<input
%(file)
s>'
)
data_template
=
(
'<div>'
data_template
=
(
'<div
class="image-thumbnail"
>'
' <img
%(image)
s>'
' <img
%(image)
s>'
' <input type="checkbox" name="
%(marker)
s">Delete</input>'
' <input type="checkbox" name="
%(marker)
s">Delete</input>'
'</div>'
'</div>'
...
...
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