I'm looking for convenient way to create ModelView, used to append a number of children to a parent when creating it. For example, I've got models:
class Order(db.Model):
__tablename__ = 'order'
id = db.Column(db.Integer, primary_key=True)
things = db.relationship('OrderList', back_populates='order', lazy='dynamic')
class OrderList(db.Model):
__tablename__ = 'order_list'
order_id = db.Column(db.Integer, db.ForeignKey('order.id'), primary_key=True)
thing_id = db.Column(db.Integer, db.ForeignKey('things.id'), primary_key=True)
amount = db.Column(db.Numeric(precision=10, scale=3))
order = db.relationship('Order', back_populates='things', lazy='joined')
thing = db.relationship('Thing', back_populates='orders', lazy='joined')
class Thing(db.Model):
__tablename__ = 'things'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(128))
orders = db.relationship('OrderList', back_populates='thing', lazy='dynamic')
stock = db.Column(db.Numeric(precision=10, scale=3))
price = db.Column(db.Numeric(precision=10, scale=3))
Simply adding that models to flask-admin, I would get an opportunity to append OrderList instances to Thing or to Order:
But how do I append children to parent without accessing middle OrderList object? Just like using One-to-many relationship.
Table scheme: