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
94df8df4
Commit
94df8df4
authored
May 04, 2020
by
Nikolay Shebanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a hook for custom SQLAlchemy model initializers (#1927)
parent
714c42bf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
5 deletions
+15
-5
view.py
flask_admin/contrib/sqla/view.py
+15
-5
No files found.
flask_admin/contrib/sqla/view.py
View file @
94df8df4
...
...
@@ -1111,6 +1111,20 @@ class ModelView(BaseModelView):
return
super
(
ModelView
,
self
)
.
handle_view_exception
(
exc
)
def
build_new_instance
(
self
):
"""
Build new instance of a model. Useful to override the Flask-Admin behavior
when the model has a custom __init__ method.
"""
model
=
self
.
_manager
.
new_instance
()
# TODO: We need a better way to create model instances and stay compatible with
# SQLAlchemy __init__() behavior
state
=
instance_state
(
model
)
self
.
_manager
.
dispatch
.
init
(
state
,
[],
{})
return
model
# Model handlers
def
create_model
(
self
,
form
):
"""
...
...
@@ -1120,11 +1134,7 @@ class ModelView(BaseModelView):
Form instance
"""
try
:
model
=
self
.
_manager
.
new_instance
()
# TODO: We need a better way to create model instances and stay compatible with
# SQLAlchemy __init__() behavior
state
=
instance_state
(
model
)
self
.
_manager
.
dispatch
.
init
(
state
,
[],
{})
model
=
self
.
build_new_instance
()
form
.
populate_obj
(
model
)
self
.
session
.
add
(
model
)
...
...
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