Hello ,
I'm having an issue with Hybrid methods - I still don't understand them
enough properly . So I have a parent and child many to many relationship
This is the child model
class FinishedGoodsChild(TimestampMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
hold_qty = db.Column(db.Float, default=0)
pen_qty = db.Column(db.Float, default=0)
qty = db.Column(db.Float, nullable=False, default=0)
sku = db.Column(db.String(40), nullable=False, default='')
size = db.relationship('SizeMaster',
secondary='size_goods_child', passive_deletes=True,
backref='size_goods_child', lazy='joined')
size_id = db.Column(db.Integer, nullable=False, default=None)
This is the Parent model
class FinishedGoodsChild(TimestampMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
qty = db.Column(db.Float, default=0)
balance = db.Column(db.Float)
children = db.relationship('FinishedGoodsChild',
passive_deletes=True, secondary='goods_child_sizes',
backref='goods_child_sizes', lazy='joined')
No I need to filter by the sum of the children qty
Here is the hybrid property that I have set up , but throws not implemented
error
@hybrid_property
def balance(self):
return sum(acc.qty for acc in self.children) @balance.expression
def balance(cls):
return sum(acc.qty for acc in cls.children)
Help is much appreciated thanks!
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/ba1add47-9497-4b92-8cb8-926e03c958a5n%40googlegroups.com.