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):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
Help is much appreciated thanks!
You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/4_H-6lP3d_k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CAFHwexfvqQs6c%2BtR20pkojBt4JjToWB7gxW7U9O4Pb_gxpxC3A%40mail.gmail.com.
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)
def __init__(self, qty, sku, size):self.qty = qtyself.sku = skuself.size_id = size.idself.size.append(size)db.Table('size_goods_child',db.Column('size_id', db.Integer, db.ForeignKey(),db.Column('goods_id', db.Integer, db.ForeignKey())class FinishedGoodsChildSchema(ma.ModelSchema):id = field_for(FinishedGoodsChild, 'id', dump_only=True)qty = field_for(FinishedGoodsChild, 'qty', dump_only=True)hold_qty = field_for(FinishedGoodsChild, 'hold_qty', dump_only=True)pen_qty = field_for(FinishedGoodsChild, 'pen_qty', dump_only=True)sku = field_for(FinishedGoodsChild, 'sku', dump_only=True)size = ma.Nested(SizeMasterSchema, many=True)class meta:model = FinishedGoodsChilddb.Table('hsn_goods',db.Column('hsn_id', db.Integer, db.ForeignKey(),db.Column('goods_id', db.Integer, db.ForeignKey())class FinishedGoods(SearchableMixin, TimestampMixin, db.Model):__searchable__ = ['balance','created', 'updated', 'title', 'description', 'sku','qty','product_category', 'fabric_combination', 'print_technique', 'design_number']id = db.Column(db.Integer, primary_key=True)filter_tags = db.relationship('FilterTags', passive_deletes=True, secondary='filter_tags_goods', backref='filter_tags_goods', lazy='joined')product_category = db.relationship('ProductCategory', passive_deletes=True, secondary='product_category_goods', backref='product_category_goods', lazy='joined')fabric_combination = db.relationship('FabricCombination', passive_deletes=True, secondary='fabric_combination_goods', backref='fabric_combination_goods', lazy='joined')print_technique = db.relationship('PrintTechnique', passive_deletes=True, secondary='print_technique_goods', backref='print_technique_goods', lazy='joined')design_number = db.relationship('DesignNumber', passive_deletes=True, secondary='design_number_goods', backref='design_number_goods', lazy='joined')uom = db.relationship('Uom',secondary='uom_goods', passive_deletes=True, backref='uom_goods', lazy='joined')hsn = db.relationship('Hsn',secondary='hsn_goods', passive_deletes=True, backref='hsn_goods', lazy='joined')
size = db.relationship('SizeMaster',
secondary='size_goods', passive_deletes=True, backref='size_goods', lazy='joined')size_chart = db.relationship('SizeChart',secondary='size_chart_goods', passive_deletes=True, backref='size_chart_goods', lazy='joined')# Foreign Key IDs for Unique Constraintproduct_category_id = db.Column(db.Integer, nullable=False)fabric_combination_id = db.Column(db.Integer, nullable=False)print_technique_id = db.Column(db.Integer, nullable=False)design_number_id = db.Column(db.Integer, nullable=False)uom_id = db.Column(db.Integer, nullable=False)
size_id = db.Column(db.Integer, nullable=False, default=None)
# End FKtitle = db.Column(db.String(100), nullable=False)description = db.Column(db.String(250), nullable=False)price = db.Column(db.Float, nullable=False, default="0")qty = db.Column(db.Float, nullable=False)
hold_qty = db.Column(db.Float, default=0)pen_qty = db.Column(db.Float, default=0)
gst = db.Column(db.Integer, nullable=False, default="0")multiple = db.Column(db.Integer, nullable=False, default=1)sku = db.Column(db.String(40), nullable=False)image = db.Column(db.String(250))
children = db.relationship('FinishedGoodsChild',passive_deletes=True, secondary='goods_child_sizes', backref='goods_child_sizes', lazy='joined')
balance = db.Column(db.Float , default= 0)__table_args__ = (db.UniqueConstraint('product_category_id', 'fabric_combination_id', 'print_technique_id', 'design_number_id', 'sku', name='finished_goods_chk_id'), )def __init__(self, product_category, fabric_combination, print_technique, design_number, uom, size, title, description, sku, price, qty, multiple):self.product_category_id = product_category.idself.product_category.append(product_category)self.fabric_combination_id = fabric_combination.idself.fabric_combination.append(fabric_combination)self.print_technique_id = print_technique.idself.print_technique.append(print_technique)self.design_number_id = design_number.idself.design_number.append(design_number)self.uom_id = uom.idself.uom.append(uom)self.size_id = size.idself.size.append(size)self.title = titleself.description = descriptionself.price = priceself.qty = qtyself.multiple = multipleself.sku = skudef get_gen_name(self):goods_name = "{}/{}/{}/{}".format(self.product_category[0].name, self.fabric_combination[0].name, self.print_technique[0].name, self.design_number[0].name)return goods_name
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CAFHwexdPMkEcg3ujiH8sWz6rDgztJLose6LPC9wsJttu4SQ5gg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CAFHwexeOqttoMT48Uw3H%2BKD3URk_XGEi-mVR7xD30o7ANBJk_A%40mail.gmail.com.