Skip to content

Commit

Permalink
Add support for frozen fields
Browse files Browse the repository at this point in the history
  • Loading branch information
falko17 committed May 11, 2021
1 parent c8877df commit b4602ad
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion flask_admin/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,11 @@ class MyModelView(ModelView):
Customized rules for the create form. Override `form_rules` if present.
"""

freeze_fields = False
"""
Keep field contents when clicking on "Save and Add Another".
"""

# Actions
action_disallowed_list = ObsoleteAttr('action_disallowed_list',
'disallowed_actions',
Expand Down Expand Up @@ -2090,7 +2095,10 @@ def create_view(self):
if model:
flash(gettext('Record was successfully created.'), 'success')
if '_add_another' in request.form:
return redirect(request.url)
# if the content of the fields should remain, we don't redirect.
# this way the model is created without changing page contents.
if not self.freeze_fields:
return redirect(request.url)
elif '_continue_editing' in request.form:
# if we have a valid model, try to go to the edit view
if model is not True:
Expand Down

0 comments on commit b4602ad

Please sign in to comment.