Closed kurtforrester closed 5 years ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Feel free to reopen it if it's still relevant to you. Thank you
Environment
Flask-Appbuilder version:
pip freeze output:
Describe the expected results
I am trying to build a custom form which will find its way into a structured multi-model query which will eventually produce a PDF report... The form will take query criteria via form fields to construct the query. I can build the custom form and then populate some of the select fields with values from the database models but when I submit I get a validation error. This is some non-specific code which produces the error which is largely from the sqlalchemy and flask app-builder sites.
association_table = Table('association', Model.metadata, Column('left_id', Integer, ForeignKey('left.id')), Column('right_id', Integer, ForeignKey('right.id')) )
class Person(Model):
class Parent(Person): tablename = 'left' id = Column(Integer, ForeignKey('person.id'), primary_key=True) children = relationship( "Child", secondary=association_table, back_populates="parents")
class Child(Person): tablename = 'right' id = Column(Integer, ForeignKey('person.id'), primary_key=True) parents = relationship( "Parent", secondary=association_table, back_populates="children")
from .models import Parent, Child from .forms import MyForm
@appbuilder.app.errorhandler(404) def page_not_found(e): return render_template('404.html', base_template=appbuilder.base_template, appbuilder=appbuilder), 404
class ParentModelView(ModelView): datamodel = SQLAInterface(Parent) list_columns = ['name', 'children'] show_columns = list_columns edit_columns = list_columns
class ChildModelView(ModelView): datamodel = SQLAInterface(Child) list_columns = ['name', 'parents'] show_columns = list_columns edit_columns = list_columns
class ParentRelatedModelView(ModelView): datamodel = SQLAInterface(Parent) related_views = [ChildModelView] list_columns = ['name', 'children'] show_columns = list_columns edit_columns = list_columns
class ChildRelatedModelView(ModelView): datamodel = SQLAInterface(Child) related_views = [ParentModelView] list_columns = ['name', 'parents'] show_columns = list_columns edit_columns = list_columns
class MasterGroupChildView(MasterDetailView): datamodel = SQLAInterface(Parent) related_views = [ChildModelView]
class MyFormView(SimpleFormView):
db.create_all()
appbuilder.add_view(MyFormView, "MyFormView", icon="fa-search", label='Form', category="Form", category_icon="fa-group")
appbuilder.add_view(ParentModelView, "ParentModelView", icon="fa-folder-open-o", category="Category", category_icon='fa-envelope') appbuilder.add_view(ChildModelView, "ChildModelView", icon="fa-folder-open-o", category="Category", category_icon='fa-envelope') appbuilder.add_separator("Category") appbuilder.add_view(ParentRelatedModelView, "ParentRelatedModelView", icon="fa-cogs", category="Category", category_icon='fa-envelope') appbuilder.add_view(ChildRelatedModelView, "ChildRelatedModelView", icon="fa-cogs", category="Category", category_icon='fa-envelope') appbuilder.add_separator("Category") appbuilder.add_view(MasterGroupChildView, "MasterGroupChildView", icon="fa-cogs", category="Category", category_icon='fa-envelope')
Describe the actual results
When the form is loaded the choices are populated as expected. Navigating the form and selecting/filling as expected. When save is pressed there is an exception in the form
pre_validation
.Steps to reproduce
Create a typical FAB project (+admin +testdata). Navigate to the form and populate the fields followed by press Save button.