Skip to content

Instantly share code, notes, and snippets.

@EdMan1022
Created August 11, 2018 23:27
Show Gist options
  • Save EdMan1022/4ad69ff22eba6ed2bcb1ff95dbaca75d to your computer and use it in GitHub Desktop.
Save EdMan1022/4ad69ff22eba6ed2bcb1ff95dbaca75d to your computer and use it in GitHub Desktop.
from .base_model import BaseModel
from ..extensions import db
from .classes.foreign_key_cascade import ForeignKeyCascade
# Association table between Payment and Subscription
payment_subscription = db.Table(
'payment_subscription',
db.Column('payment_id', db.Integer, db.ForeignKey('payment.id'), primary_key=True),
db.Column('subscription_id', db.Integer, db.ForeignKey('subscription.id'),
primary_key=True)
)
# Association table between Payment and OrderedProduct
payment_ordered_product = db.Table(
'payment_ordered_product',
db.Column('payment_id', db.Integer, db.ForeignKey('payment.id'), primary_key=True),
db.Column('ordered_product_id', db.Integer, db.ForeignKey('ordered_product.id'),
primary_key=True)
)
class Payment(BaseModel):
"""Ties an Order to the credit card charge that pays for the items that make it up"""
id = db.Column(db.Integer, primary_key=True)
order_id = db.Column(db.Integer, ForeignKeyCascade('order.id'))
subscription = db.relationship('Subscription', secondary=payment_subscription, backref=db.backref('payment'))
ordered_product = db.relationship('OrderedProduct', secondary=payment_ordered_product,
backref=db.backref('payment'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment