inline_models don't work for one-to-many
See original GitHub issueI’ve not been able to make inline_models forms for one-to-many, and I think it’s linked to this line: https://github.com/flask-admin/flask-admin/blob/master/flask_admin/contrib/sqla/form.py#L561
class Company(Model):
id = db.Column(db.Integer, primary_key=True)
address_id = db.Column(db.Integer, db.ForeignKey('address.id'))
address = db.relationship('Address', backref='companies')
class Address(Model):
id = db.Column(db.Integer, primary_key=True)
class CompanyModelView(ModelView):
inline_models = (Address, )
That gives me the following exception: Exception: Cannot find reverse relation for model <class 'app.models.address.Address'>
Wondering if I’m missing something, or if this is per design ? It seems possible to change the key resolution method there to support the one-to-many.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:21
- Comments:7 (2 by maintainers)
Top Results From Across the Web
one-to-many inline select with django admin - Stack Overflow
It does work, but it will bite you later (for instance, in the first line of Student ). And, class = models.ForeignKey(Class) won't...
Read more >[Solved]-Showing partial tabular inline models in Django-django
Inline admins (like TabularInline ) are only used when you have a one-to-many relation, which is created by a ForeignKey on the many...
Read more >Source code for flask_admin.contrib.sqla.form - Flask-Admin
'MANYTOONE': kwargs['allow_blank'] = True if not ... None # Current Unique Validator does not work with multicolumns-pks if not has_multiple_pks(model): ...
Read more >Model creation, ForeignKey relations and the Django Admin
the Profile Model has a OneToOne relationship with the User model. ... call the full_clean() method of the instance, as simply saving the...
Read more >In admin, is there a post-commit hook that is executed after all ...
point in the admin save process as save_model(), this also did not work. ... main model and inline models are combined into a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
models.py
views.py
A quick workaround is to apply the inline model to the inverse relationship. For example in OPs original example instead of applying the inline mode to
CompanyModelView
you would do:While this isn’t exactly what was asked for, it does allow you to achieve the goal of creating both models on one webpage.