class StockPrice(db.Model): __tablename__ = 'stock_prices' id = db.Column(db.Integer, primary_key=True) date = db.Column(db.Date) stock_id = db.Column(db.Integer, db.ForeignKey('stocks.id')) opn = db.Column(db.Float) high = db.Column(db.Float) low = db.Column(db.Float) close = db.Column(db.Float) volume = db.Column(db.Float) adjclose = db.Column(db.Float) stock = db.relationship("Stock") def __init__(self, date, stock, opn, high, low, close, volume, adjclose): self.date = date self.stock = stock self.opn = opn self.high = high self.low = low self.close = close self.volume = volume self.adjclose = adjclose def __repr__(self): return "<StockPrice('%s, %s, %s, %f')>" % (self.id or '', self.date, self.stock, self.close)
class Budget(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(60)) budget = db.Column(db.Float) closed = db.Column(db.Boolean, default=False) term_id = db.Column(db.Integer, db.ForeignKey('term.id')) expenditures = db.relationship('Expenditure', backref='budget', lazy=True)
class Transaction(db.Model): id = db.Column(db.Integer, primary_key=True) tdate = db.Column(db.Date) category_id = db.Column(db.Integer, db.ForeignKey('category.id')) file_id = db.Column(db.Integer, db.ForeignKey('trans_file.id')) name = db.Column(db.String) amount = db.Column(db.Float) bdate = db.Column(db.Date) yearly = db.Column(db.Boolean, default=False) category = db.relationship("Category") trans_file = db.relationship("TransFile") def __init__(self, tdate, name, category, amount, trans_file, bdate=None, yearly=False): self.tdate = tdate self.name = name self.amount = amount self.bdate = bdate or self.tdate self.yearly = yearly if isinstance(category, int): self.category_id = category else: self.category = category if isinstance(trans_file, int): self.file_id = trans_file else: self.trans_file = trans_file def __repr__(self): return "<Tran('%d, %s, %s, %s, %s, %s, %s')>" % ( (self.id or 0), self.tdate, self.name, self.category, self.amount, self.trans_file, self.bdate)
class Stock(db.Model): __tablename__ = 'stocks' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String) long_name = db.Column(db.String) prices = db.relationship("StockPrice") def __init__(self, name, long_name=None): self.name = name self.long_name = long_name or name def __repr__(self): return "<Stock('%s, %s, %s')>" % (self.id or '', self.name, self.long_name)
class Account(db.Model): account_id = db.Column(db.Integer, primary_key=True) holder_name = db.Column(db.String(30), nullable=False) account_type = db.Column(db.String(20), nullable=False, default='Resident') block_no = db.Column(db.String(1), nullable=True) phone_no = db.Column(db.String(10), nullable=False) flat_no = db.Column(db.Integer, nullable=True, unique=True) balance = db.Column(db.Float, default=0.0, nullable=False) transactions = db.relationship('Transactions', backref='ref_acc', lazy=True) init_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) def __repr__(self): return "Account('{}', '{}', '{}')".format(self.account_id, self.account_type, self.holder_name)
class CategoryRE(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String) category_id = db.Column(db.Integer, db.ForeignKey('category.id')) pattern = db.Column(db.String) yearly = db.Column(db.Boolean, default=False) category = db.relationship("Category") def __init__(self, name, category, pattern, yearly=False): self.name = name self.category = category self.pattern = pattern self.yearly = yearly def __repr__(self): return "<CategoryRE('%s, %s, %s')>" % (self.name, self.category.name, self.pattern)
class Category(db.Model): id = db.Column(db.Integer, primary_key=True) parent_id = db.Column(db.Integer, db.ForeignKey('category.id')) name = db.Column(db.String) depth = db.Column(db.Integer, default=0) children = db.relationship("Category", backref=db.backref('parent', remote_side=[id])) def __init__(self, name, parent=None, depth=0): self.name = name if parent: self.parent = parent self.depth = parent.depth + 1 else: self.depth = depth def __repr__(self): return "<Category('%s')>" % (self.name)
class Term(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(60)) income = db.Column(db.Float) budgets = db.relationship('Budget', backref='term', lazy=True)