class Item(db.Model): id = db.Column(db.Integer, primary_key=True) number = db.Column(db.String(255), unique=True) description = db.Column(db.String(255)) retail = db.Column(db.Float) whole = db.Column(db.Float) last_update = db.Column(db.DateTime, default=datetime.utcnow) storage = db.relationship("Storage", backref="item", lazy='dynamic') order_details = db.relationship("OrderDetail", backref="item", lazy='dynamic') income_details = db.relationship("IncomeDetail", backref="item", lazy='dynamic') reservations = db.relationship("Reservation", backref="item", lazy='dynamic') def __init__(self, number=None, description=None, \ last_update=None, retail = None, whole = None): if number and description != None: self.number = number self.description = description if last_update: self.last_update = last_update if retail: self.retail = retail if whole: self.whole = whole else: raise ValueError def __repr__(self): return '{ Item Object: %s , %s , %s }' % \ (self.number, self.description, self.last_update)
class Reservation(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255)) contact = db.Column(db.String(255)) address = db.Column(db.String(255)) note = db.Column(db.Text) date = db.Column(db.DateTime, default=datetime.utcnow) amount = db.Column(db.Integer) # 0: not finish ; 1: finish; -1: can't finish, also means delete status = db.Column(db.Integer, default=0) item_id = db.Column(db.Integer, db.ForeignKey('item.id')) def __init__(self, name, contact, address, item_id, amount, note=None): self.name = name self.contact = contact self.address = address self.item_id = item_id self.amount = amount if note: self.note = note def __repr__(self): return "{{-- Reservation Object: %s --}}" % self.name
class Account(db.Model): id = db.Column(db.Integer, primary_key=True) user_no = db.Column(db.String(255), unique=True) user_ps = db.Column(db.String(255)) privilege = db.Column(db.Integer, default=0) last_login = db.Column(db.DateTime,default=datetime.utcnow) last_ip = db.Column(db.String(255)) place_id = db.Column(db.Integer, db.ForeignKey('place.id')) def __init__(self, user_no=None, user_ps=None, privilege=None, place_id=None): if user_no and user_ps and place_id: self.user_no = user_no self.user_ps = md5(user_ps) self.place_id = place_id if privilege: self.privilege = privilege else: raise ValueError def __repr__(self): return '{ Account Object: %s , %s , %s , %s }' % \ (self.user_no, self.user_ps, \ self.privilege, self.place_id)
class Place(db.Model): id = db.Column(db.Integer, primary_key=True) place = db.Column(db.String(255), unique=True) person = db.relationship("Account", backref="place", lazy='dynamic') storage = db.relationship("Storage", backref="place", lazy='dynamic') order = db.relationship("Order", backref="place", lazy='dynamic') def __init__(self, place=None): if place: self.place = place else: raise ValueError def __repr__(self): return '{ Place Object: %s , %s }' % \ (self.id, self.place)
class IncomeDetail(db.Model): id = db.Column(db.Integer, primary_key=True) size = db.Column(db.String(255)) amount = db.Column(db.Integer) item_id = db.Column(db.Integer, db.ForeignKey('item.id')) income_id = db.Column(db.Integer, db.ForeignKey('income.id')) def __init__(self, item_id=None, income_id=None, \ size=None, amount=None): if item_id and income_id and size and amount: self.item_id = item_id self.income_id = income_id self.size = size self.amount = amount else: raise ValueError def __repr__(self): return '{ IncomeDetail Object: %s , %s , %s , %s }' % \ (self.item_id, self.income_id, self.size, self.amount)
class Storage(db.Model): id = db.Column(db.Integer, primary_key=True) size = db.Column(db.String(255), unique=True) amount = db.Column(db.Integer) item_id = db.Column(db.Integer, db.ForeignKey('item.id')) place_id = db.Column(db.Integer, db.ForeignKey('place.id')) def __init__(self, size=None, amount=None, \ item_id=None, place_id=None): if size and amount and item_id and place_id: self.size = size self.amount = amount self.item_id = item_id self.place_id = place_id else: raise ValueError def __repr__(self): return '{ Storage Object: %s , %s , %s , %s }' % \ (self.size, self.amount, \ self.item_id, self.place_id)