Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Required fields for many-to-many relationships #30

Closed
leonth opened this issue Jun 7, 2012 · 2 comments
Closed

Required fields for many-to-many relationships #30

leonth opened this issue Jun 7, 2012 · 2 comments

Comments

@leonth
Copy link

leonth commented Jun 7, 2012

Hi, I tried using flask-admin for a many-to-many relationship defined in SQLAlchemy like so: http://docs.sqlalchemy.org/en/rel_0_7/orm/tutorial.html#building-a-many-to-many-relationship

The UI works great, however because the fields are designated as "required", on a blank database I am not able to use the UI to add any rows to the database. The forms to add rows in both tables will give an error "This field is required.", and the select box is empty because the other table is still empty. What should I do?

@mrjoes
Copy link
Member

mrjoes commented Jun 7, 2012

Uh, you have M2M in both directions?

@khamukhin
Copy link

Some workaround. I've used "form_args" and "wtf.Optional()" to fix such problem with M2M relationships.

class MyModelView(ModelView):
    form_args = dict(
        reports=dict(validators=[wtf.Optional()]),
        products=dict(validators=[wtf.Optional()])
    )

admin = Admin(app, name='My Admin')
admin.add_view(MyModelView(MyModel, db.session))

@mrjoes mrjoes closed this as completed Aug 12, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants