class Event(Thing): __tablename__ = 'event' id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True) parent_id = db.Column(db.Integer, db.ForeignKey('event.id')) parent = db.relationship('Event', remote_side=[id], foreign_keys=[parent_id]) door_time = db.Column(db.DateTime, index=True) start_time_ = db.Column('start_time', db.DateTime, index=True) end_time = db.Column(db.DateTime, index=True) @property def start_time(self): eastern = timezone('US/Eastern') return self.start_time_.replace(tzinfo=pytz.UTC).astimezone(eastern) @start_time.setter def start_time(self, value): self.start_time_ = value start_time = synonym('start_time_', descriptor=start_time) maximum_attendee_capacity = db.Column(db.Integer) child_events = db.relationship('Event', foreign_keys=[parent_id]) audience_id = db.Column(db.Integer, db.ForeignKey('audience.id')) audience = db.relationship("Audience", foreign_keys=[audience_id]) # Slug for site url slug = db.Column(db.String(256)) # Shorthand code that will show up on the calendar calendar_code = db.Column(db.String(16)) # Two images per show/event primary_image = db.Column(db.String(128)) secondary_image = db.Column(db.String(128)) offers = db.relationship('Offer', secondary=event_offer) #tickets = db.relationship('Ticket', back_populates='event') is_active = db.Column(db.Boolean, default=True) is_basic = db.Column(db.Boolean, default=True) def __repr__(self): return '<Event {}: {}>'.format(self.name, self.start_time) __mapper_args__ = { 'polymorphic_identity': 'event', }
class Payment(Thing): __tablename__ = 'payment' id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True) payment_type = db.Column(db.String(32)) credit_card_id = db.Column(db.Integer, db.ForeignKey('credit_card.id')) credit_card = db.relationship('CreditCard', backref='payment', foreign_keys=[credit_card_id]) __mapper_args__ = { 'polymorphic_identity': 'payment', }
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) body = db.Column(db.Text) timestamp = db.Column(db.DateTime, index=True, default=datetime.now) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) author = db.relationship('User', foreign_keys=[user_id]) thing_id = db.Column(db.Integer, db.ForeignKey('thing.id')) thing = db.relationship('Thing', foreign_keys=[thing_id]) def __repr__(self): return '<Post {}>'.format(self.body)
class Order(Thing): __tablename__ = 'order' id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True) __mapper_args__ = { 'polymorphic_identity': 'order', }
class Ticket(Thing): id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True) face_value = db.Column(db.Numeric(12, 2)) event_id = db.Column(db.Integer, db.ForeignKey('event.id')) event = db.relationship('Event', foreign_keys=[event_id]) reservation_id = db.Column(db.Integer, db.ForeignKey('reservation.id')) reservation = db.relationship('Reservation', foreign_keys=[reservation_id], backref='tickets') offer_id = db.Column(db.Integer, db.ForeignKey('offer.id')) offer = db.relationship('Offer', foreign_keys=[offer_id]) __mapper_args__ = {'polymorphic_identity': 'ticket'}
class LineItem(Thing): __tablename__ = 'line_item' id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True) transaction_request_id = db.Column(db.Integer, db.ForeignKey('transaction_request.id')) transaction_request = db.relationship( 'TransactionRequest', foreign_keys=[transaction_request_id], backref='line_items') unit_price = db.Column(db.Numeric(12, 2)) fee = db.Column(db.Numeric(12, 2)) quantity = db.Column(db.Integer) __mapper_args__ = { 'polymorphic_identity': 'line_item', }
class CustomerData(Thing): __tablename__ = 'customer_data' id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True) email = db.Column(db.String(128)) phone = db.Column(db.String(32)) __mapper_args__ = { 'polymorphic_identity': 'customer_data', }
class Reservation(Thing): __tablename__ = 'reservation' id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True) booking_time = db.Column(db.DateTime, default=datetime.now) reservation_for_id = db.Column(db.Integer, db.ForeignKey('event.id')) reservation_for = db.relationship('Event', foreign_keys=[reservation_for_id], backref='reservations') under_name = db.Column(db.String(256)) total_price = db.Column(db.Numeric(12, 2)) transaction_request_id = db.Column(db.Integer, db.ForeignKey('transaction_request.id')) transaction_request = db.relationship( 'TransactionRequest', foreign_keys=[transaction_request_id]) __mapper_args__ = {'polymorphic_identity': 'reservation'}
class CreditCard(Thing): __tablename__ = 'credit_card' id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True) number = db.Column(db.String(32)) card_code = db.Column(db.String(8)) expiration_date = db.Column(db.String(8)) __mapper_args__ = { 'polymorphic_identity': 'credit_card', }
class TransactionResponse(Thing): __tablename__ = 'transaction_response' id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True) response_code = db.Column(db.String(16)) approved = db.Column(db.Boolean) response_body = db.Column(db.Text) __mapper_args__ = { 'polymorphic_identity': 'transaction_response', }
class Audience(Thing): __tablename__ = 'audience' id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True) # The target group associated with a given audience # (e.g. veterans, car owners, musicians, etc.) audience_type = db.Column(db.String(256)) # events = db.relationship('Event', backref='audience', lazy='dynamic') __mapper_args__ = { 'polymorphic_identity': 'audience', }
class CustomerAddress(Thing): __tablename__ = 'customer_address' id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True) first_name = db.Column(db.String(256)) last_name = db.Column(db.String(256)) company = db.Column(db.String(256)) address = db.Column(db.String(256)) city = db.Column(db.String(256)) state = db.Column(db.String(256)) zip = db.Column(db.String(256)) __mapper_args__ = { 'polymorphic_identity': 'customer_address', }
class TransactionRequest(Thing): __tablename__ = 'transaction_request' id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True) # The amount of the transaction request amount = db.Column(db.Numeric(12, 2)) taxes = db.Column(db.Numeric(12, 2)) fees = db.Column(db.Numeric(12, 2)) payment_id = db.Column(db.Integer, db.ForeignKey('payment.id')) payment = db.relationship('Payment', backref='transaction_request', foreign_keys=[payment_id]) order_id = db.Column(db.Integer, db.ForeignKey('order.id')) order = db.relationship('Order', backref='transaction_request', foreign_keys=[order_id]) customer_address_id = db.Column(db.Integer, db.ForeignKey('customer_address.id')) bill_to = db.relationship('CustomerAddress', backref='transaction_request', foreign_keys=[customer_address_id]) customer_data_id = db.Column(db.Integer, db.ForeignKey('customer_data.id')) customer = db.relationship('CustomerData', backref='transaction_request', foreign_keys=[customer_data_id]) transaction_response_id = db.Column( db.Integer, db.ForeignKey('transaction_response.id')) transaction_response = db.relationship( 'TransactionResponse', backref='transaction_request', foreign_keys=[transaction_response_id]) __mapper_args__ = { 'polymorphic_identity': 'transaction_request', }
from juniper.app.main.models import Thing from juniper.app import db from sqlalchemy.orm import synonym from pytz import timezone import pytz event_offer = db.Table( 'event_offer', db.Column('event_id', db.Integer, db.ForeignKey('event.id')), db.Column('offer_id', db.Integer, db.ForeignKey('offer.id'))) class Event(Thing): __tablename__ = 'event' id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True) parent_id = db.Column(db.Integer, db.ForeignKey('event.id')) parent = db.relationship('Event', remote_side=[id], foreign_keys=[parent_id]) door_time = db.Column(db.DateTime, index=True) start_time_ = db.Column('start_time', db.DateTime, index=True) end_time = db.Column(db.DateTime, index=True) @property def start_time(self): eastern = timezone('US/Eastern')