Open klothe opened 9 years ago
Flask-Admin can't find relationship
from model C
to model B
. Add backref
:
class B(A):
__mapper_args__ = {'polymorphic_identity': 'b'}
c = relationship(C, backref='b')
Sorry, my original description of the problem was wrong--it just happens that forgetting the backref causes the same error message. I've updated the example code.
OK, sorry for taking to long to respond.
InlineModels only work with directly related models. In your case it is A to B (or vice a versa), C to D, A to C. B and D are not directly related and Flask-Admin cannot figure out what to do.
I am having a similar issue. I have a model Invitation
that has a relationship to Employee
. Employee
is a subclass of User
. Right now the inline model fails. That being said, the relationship does not in any way involve User
. I would think this should work and that flask admin should not just fall back to the base class here:
# Find property from target model to current model
# Use the base mapper to support inheritance
target_mapper = info.model._sa_class_manager.mapper.base_mapper
If you define a parallel hierarchy of model classes where class A has a subclass B, class C has a subclass D, and A has a relationship to C,
it is not possible to instantiate a ModelView of B with D as an inline model, like this:
This fails with the error:
Here is the full code to reproduce the error with Flask-Admin 1.1.0 and SQLAlchemy 1.0.4:
If the relationship from A to C is moved "downward", i.e. replaced with a relationship from B to D, there is no error.