diff --git a/flask_appbuilder/baseviews.py b/flask_appbuilder/baseviews.py index ad1dc73795..0dc908c4b2 100644 --- a/flask_appbuilder/baseviews.py +++ b/flask_appbuilder/baseviews.py @@ -1222,7 +1222,7 @@ def _add(self): item = self.datamodel.obj() try: - form.populate_obj(item) + self.populate_item_from_form(form, item, True) self.pre_add(item) except Exception as e: flash(str(e), "danger") @@ -1266,7 +1266,7 @@ def _edit(self, pk): self.process_form(form, False) try: - form.populate_obj(item) + self.populate_item_from_form(form, item, False) self.pre_update(item) except Exception as e: flash(str(e), "danger") @@ -1380,6 +1380,13 @@ def is_get_mutation_allowed(self) -> bool: request.method == "GET" and self.appbuilder.app.extensions.get("csrf") ) + def populate_item_from_form(self, form, item, is_created): + """ + Populate the properties of the item to be created or updated based + on the content of the form. + """ + form.populate_obj(item) + def prefill_form(self, form, pk): """ Override this, will be called only if the current action is rendering