class MarketDay(Base): __table_args__ = {'extend_existing': True} __tablename__ = 'market_days' market_day_id = db.Column(db.Integer, autoincrement=True, primary_key=True) date = db.Column(db.Date) ## NOT NULL day = db.Column(postgresql.ENUM(Day)) ## NOT NULL opens = db.Column(db.Time(timezone=True)) ## NOT NULL closes = db.Column(db.Time(timezone=True)) ## NOT NULL created_at = db.Column(db.DateTime(timezone=True), nullable=False, default=get_now()) updated_at = db.Column(db.DateTime(timezone=True), default=get_now(), onupdate=get_now()) market_id = db.Column(db.Integer, db.ForeignKey('markets.market_id')) def __init__(self, date, day, opens, closes): """ self.date = date self.day = day self.opens = opens self.closes = closes """ def __repr__(self): return str('MarketDay: ' + str(self.market_day_id) + ' ' + str(self.market_id))
class FarmerProduct( Base ): __table_args__ = { 'extend_existing': True } __tablename__ = 'farmer_products' farmer_id = db.Column( db.Integer, db.ForeignKey( 'farmers.farmer_id' ), primary_key = True ) product_id = db.Column( db.Integer, db.ForeignKey( 'products.product_id' ), primary_key = True ) price = db.Column( postgresql.MONEY ) ## NOT NULL available = db.Column( db.Boolean ) ## NOT NULL created_at = db.Column( db.DateTime( timezone = True ), nullable = False, default = get_now( ) ) updated_at = db.Column( db.DateTime( timezone = True ), default = get_now( ), onupdate = get_now( ) ) farmers = db.relationship( 'Farmer', backref = 'wares' ) products = db.relationship( 'Product', backref = 'vendors' ) def __init__( self, farmer_id, product_id ): """ price, available """ self.farmer_id = farmer_id self.product_id = product_id """ self.price = price self.available = available """ def __repr__( self ): return str( 'FarmerProduct: ' + str( self.farmer_id ) + ' ' + str( self.product_id ) )
class Ingredient(Base): __table_args__ = {'extend_existing': True} __tablename__ = 'ingredients' ingredient_id = db.Column(db.Integer, autoincrement=True, primary_key=True) ingredient_quantity = db.Column(db.String(255)) created_at = db.Column(db.DateTime(timezone=True), nullable=False, default=get_now()) updated_at = db.Column(db.DateTime(timezone=True), default=get_now(), onupdate=get_now()) recipe_id = db.Column(db.Integer, db.ForeignKey('recipes.recipe_id')) product_id = db.Column(db.Integer, db.ForeignKey('products.product_id')) def __init__(self, ingredient_quantity): ## Old names for previous database model backrefs ''' owner_recipe, owner_product ''' self.ingredient_quantity = ingredient_quantity ''' self.owner_recipe = owner_recipe self.owner_product = owner_product ''' def __repr__(self): return '<Ingredient %r' % self.ingredient_quantity
class Product( Base ): __table_args__ = { 'extend_existing': True } __tablename__ = 'products' product_id = db.Column( db.Integer, autoincrement = True, primary_key = True ) name = db.Column( db.String( 40 ), nullable = False ) created_at = db.Column( db.DateTime( timezone = True ), nullable = False, default = get_now( ) ) updated_at = db.Column( db.DateTime( timezone = True ), default = get_now( ), onupdate = get_now( ) ) category_id = db.Column( db.Integer, db.ForeignKey( 'categories.category_id' ) ) markets = db.relationship( 'MarketDay', secondary = 'product_days', backref = 'products' ) ingredients = db.relationship( 'Ingredient', backref = 'products' ) farmers = db.relationship( 'FarmerProduct', backref = 'wares' ) def __init__( self, name ): self.name = name def __repr__( self ): return str( 'Product: ' + str( self.product_id ) + ' ' + self.name + ' ' + str( self.category_id ) )
class Direction(Base): __table_args__ = {'extend_existing': True} __tablename__ = 'directions' direction_id = db.Column(db.Integer, autoincrement=True, primary_key=True) order = db.Column(db.SmallInteger) ## NOT NULL summary = db.Column(db.String(200)) instruction = db.Column(db.Text) ## NOT NULL created_at = db.Column(db.DateTime(timezone=True), nullable=False, default=get_now()) updated_at = db.Column(db.DateTime(timezone=True), default=get_now(), onupdate=get_now()) recipe_id = db.Column(db.Integer, db.ForeignKey('recipes.recipe_id')) def __init__(self, order, instruction): self.order = order self.instruction = instruction def __repr__(self): return '<Direction %r' % self.instruction
class Farmer(Base): __table_args__ = {'extend_existing': True} __tablename__ = 'farmers' farmer_id = db.Column(db.Integer, autoincrement=True, primary_key=True) first_name = db.Column(db.String(40), nullable=False) last_name = db.Column(db.String(40), nullable=False) ## Potential columns for login and registration authentication ''' gender = db.Column( db.String( 20 ) ) birthday = db.Column( db.Date ) email_address = db.Column( db.String( 75 ), unique = True ) password = db.Column( db.String( 50 ) ) phone_number = db.Column( db.String( 20 ) ) street_address = db.Column( db.Text ) city = db.Column( db.String( 40 ) ) state = db.Column( db.String( 2 ) ) zip_code = zip_code = db.Column( db.Integer( 5 ) ) ''' joined_at = db.Column(db.DateTime(timezone=True), nullable=False, default=get_now()) updated_at = db.Column(db.DateTime(timezone=True), default=get_now(), onupdate=get_now()) farm_id = db.Column(db.Integer, db.ForeignKey('farms.farm_id')) markets = db.relationship('MarketDay', secondary='farmer_days', backref='farmers') products = db.relationship('FarmerProduct', backref='vendors') def __init__(self, first_name, last_name): self.first_name = first_name self.last_name = last_name def __repr__(self): return str('Farmer: ' + str(self.farmer_id) + ' ' + self.first_name + ' ' + self.last_name)
def __repr__( self ): return str( 'FarmerProduct: ' + str( self.farmer_id ) + ' ' + str( self.product_id ) ) class Category( Base ): __table_args__ = { 'extend_existing': True } __tablename__ = 'categories' category_id = db.Column( db.Integer, autoincrement = True, primary_key = True ) group = db.Column( db.String( 30 ), nullable = False ) category = db.Column( db.String( 30 ), nullable = False ) created_at = db.Column( db.DateTime( timezone = True ), nullable = False, default = get_now( ) ) updated_at = db.Column( db.DateTime( timezone = True ), default = get_now( ), onupdate = get_now( ) ) products = db.relationship( 'Product', backref = 'categories' ) def __init__( self, category ): self.category = category def __repr__( self ): return str( 'Category: ' + str( self.category_id ) + ' ' + self.group + ' ' + self.category ) ## A many-to-many table for which day products are sold product_days = db.Table( 'product_days', Base.metadata, db.Column( 'product_id', db.Integer, db.ForeignKey( 'products.product_id' ), primary_key = True ), db.Column( 'market_day_id', db.Integer, db.ForeignKey( 'market_days.market_day_id' ), primary_key = True ) )
default=get_now(), onupdate=get_now()) farmers = db.relationship('Farmer', backref='farms') def __init__(self, name, email_address, phone_number, street_address, city, state, zip_code): self.name = name self.email_address = email_address self.phone_number = phone_number self.street_address = street_address self.city = city self.state = state self.zip_code = zip_code def __repr__(self): return str('Farm: ' + str(self.farm_id) + ' ' + self.name) ## Farmers' days at market, a many-to-many db.relationship farmer_days = db.Table( 'farmer_days', Base.metadata, db.Column('farmer_id', db.Integer, db.ForeignKey('farmers.farmer_id'), primary_key=True), db.Column('market_day_id', db.Integer, db.ForeignKey('market_days.market_day_id'), primary_key=True))