class Tag(db.Model): tag_id = db.Column(db.Integer, primary_key=True) tag_name = db.Column(db.String, unique=True, nullable=False) account_tags = db.relationship('Account_tag', backref=db.backref('Tag', uselist=True)) transaction_tags = db.relationship('Transaction_tag', backref=db.backref('Tag', uselist=True)) def __repr__(self): return '<Tag %r>' % self.tag_name
class Real_estate(db.Model): real_estate_id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False) original_value = db.Column(db.Float, nullable=False) estimated_value = db.Column(db.Float, nullable=False) transactions_re = db.relationship('Transaction_real_estate', backref=db.backref('Real_estate', uselist=False)) def __repr__(self): return '<Real Estate %r>' % self.name
class Bond(db.Model): bond_id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False) value = db.Column(db.Float, nullable=False) maturation_date = db.Column(db.Date, nullable=False, default=date.today()) transactions_bond = db.relationship('Transaction_bond', backref=db.backref('Bond', uselist=False)) def __repr__(self): return '<Bond %r>' % self.name
class Bank_account(db.Model): bank_account_id = db.Column(db.Integer, primary_key=True) bank_name = db.Column(db.String, nullable=False) account_digits = db.Column(db.String, nullable=False) interest_rate = db.Column(db.Integer, nullable=True) interest_period = db.Column(db.String, nullable = True) transactions_ba = db.relationship('Transaction_bank_account', backref=db.backref('Bank_account', uselist=False)) def __repr__(self): return '<Bank Account %r %r>' % (self.bank_name, self.account_digits)
class Stock(db.Model): stock_id = db.Column(db.Integer, primary_key=True) stock_symbol = db.Column(db.String, nullable=False) exchange = db.Column(db.String, nullable=False) num_stocks = db.Column(db.Integer, nullable=False) #Starting number of stocks transactions_stock = db.relationship('Transaction_stock', backref=db.backref('Stock', uselist=False)) # stock_ids = db.relationship('Stock_value', backref=db.backref('Stock', uselist=True)) def __repr__(self): return '<Stock %r>' % self.stock_symbol
class Account(db.Model): account_id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey(User.user_id), nullable=False) account_name = db.Column(db.String, nullable=False) account_type = db.Column(db.String, nullable=False) transactions = db.relationship('Transaction', backref=db.backref('Account', uselist=True)) account_tags = db.relationship('Account_tag', backref=db.backref('Account', uselist=True)) debts = db.relationship('Debt', backref=db.backref('Account', uselist=True)) def __repr__(self): return '<Account %r>' % self.account_name
class User(UserMixin, db.Model): user_id = db.Column(db.Integer, primary_key=True) user_name = db.Column(db.String, unique=True, nullable=False) pass_hash = db.Column(db.String, nullable=False) accounts = db.relationship('Account', backref=db.backref('User', uselist=False)) def get_id(self): return int(self.user_id) def get_username(self): return str(self.user_name) def __repr__(self): return '<User %r>' % self.user_name
class Debt(db.Model): debt_id = db.Column(db.Integer, primary_key=True) lender = db.Column(db.String, nullable=False) principal = db.Column(db.Float, nullable=False) interest_rate = db.Column(db.Float, nullable=True) interest_period = db.Column(db.String, nullable = True) payment_account = db.Column(db.Integer, db.ForeignKey(Account.account_id), nullable=False) payment_date = db.Column(db.String, nullable=True) transactions_debt = db.relationship('Transaction_debt', backref=db.backref('Debt', uselist=False)) def __repr__(self): return '<Debt %r>' % self.lender
class Transaction(db.Model): transaction_id = db.Column(db.Integer, primary_key=True) account_id = db.Column(db.Integer, db.ForeignKey(Account.account_id), nullable=False) transaction_type = db.Column(db.String, nullable=False) transaction_value = db.Column(db.Float, nullable=False) transaction_date = db.Column(db.Date, nullable=False, default=date.today()) # transaction_time = db.Column(db.Time, nullable=False) transaction_note = db.Column(db.String) transactions_ba = db.relationship('Transaction_bank_account', backref=db.backref('Transaction', uselist=True)) transactions_re = db.relationship('Transaction_real_estate', backref=db.backref('Transaction', uselist=True)) transactions_bond = db.relationship('Transaction_bond', backref=db.backref('Transaction', uselist=True)) transactions_stock = db.relationship('Transaction_stock', backref=db.backref('Transaction', uselist=True)) transactions_debt = db.relationship('Transaction_debt', backref=db.backref('Transaction', uselist=True)) transaction_tags = db.relationship('Transaction_tag', backref=db.backref('Transaction', uselist=True)) def __repr__(self): return '<Transaction %r>' % self.transaction_type
class Transaction_real_estate(db.Model): transaction_re_id = db.Column(db.Integer, primary_key=True) transaction_id = db.Column(db.Integer, db.ForeignKey(Transaction.transaction_id), nullable=False) real_estate_id = db.Column(db.Integer, db.ForeignKey(Real_estate.real_estate_id), nullable=False)
class Transaction_debt(db.Model): transaction_debt_id = db.Column(db.Integer, primary_key=True) transaction_id = db.Column(db.Integer, db.ForeignKey('transaction.transaction_id'), nullable=False) debt_id = db.Column(db.Integer, db.ForeignKey('debt.debt_id'), nullable=False)
class Transaction_bank_account(db.Model): transaction_ba_id = db.Column(db.Integer, primary_key=True) transaction_id = db.Column(db.Integer, db.ForeignKey(Transaction.transaction_id), nullable=False) bank_account_id = db.Column(db.Integer, db.ForeignKey(Bank_account.bank_account_id), nullable=False)
class Account_tag(db.Model): account_tag_id = db.Column(db.Integer, primary_key=True) account_id = db.Column(db.Integer, db.ForeignKey(Account.account_id), nullable=False) tag_id = db.Column(db.Integer, db.ForeignKey(Tag.tag_id), nullable=False)
class Transaction_tag(db.Model): transaction_tag_id = db.Column(db.Integer, primary_key=True) transaction_id = db.Column(db.Integer, db.ForeignKey(Transaction.transaction_id), nullable=False) tag_id = db.Column(db.Integer, db.ForeignKey(Tag.tag_id), nullable=False)
class Transaction_stock(db.Model): transaction_stock_id = db.Column(db.Integer, primary_key=True) transaction_id = db.Column(db.Integer, db.ForeignKey(Transaction.transaction_id), nullable=False) stock_id = db.Column(db.Integer, db.ForeignKey(Stock.stock_id), nullable=False)
class Transaction_bond(db.Model): transaction_bond_id = db.Column(db.Integer, primary_key=True) transaction_id = db.Column(db.Integer, db.ForeignKey(Transaction.transaction_id), nullable=False) bond_id = db.Column(db.Integer, db.ForeignKey(Bond.bond_id), nullable=False)