class User(db.Model, UserMixin): __tablename__ = 'auth_user' id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(255), nullable=False, unique=True) password = db.Column(db.String(255)) active = db.Column('is_active', db.Boolean(), nullable=False, default=True) username = db.Column(db.String(128), nullable=False, default=' ') first_name = db.Column(db.String(30), nullable=False, default=' ') last_name = db.Column(db.String(30), nullable=False, default=' ') is_staff = db.Column(db.Boolean(), nullable=False, default=False) is_superuser = db.Column(db.Boolean(), nullable=False, default=False) last_login = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now) date_joined = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now) roles = db.relationship(Role, secondary=roles_users, backref=db.backref('users')) def __unicode__(self): return u'{0} {1}'.format(self.id, self.email) def has_any_perm(self, *perms): has = set( itertools.chain.from_iterable(role.permissions for role in self.roles)) return self.is_superuser or has.intersection(perms)
class ExchangeRate(db.Model): __tablename__ = 'exchange_rate' id = db.Column(db.Integer, primary_key=True) create_at = db.Column(db.DateTime, default=datetime.datetime.now) name = db.Column(db.String(255)) date_time = db.Column(db.DateTime, default=datetime.datetime.now) source_id = db.Column(db.Integer, db.ForeignKey(Amount.id)) source = db.relationship(Amount, foreign_keys=source_id, backref=db.backref('source_amounts', lazy='joined')) compare_id = db.Column(db.Integer, db.ForeignKey(Amount.id)) compare = db.relationship(Amount, foreign_keys=compare_id, backref=db.backref('compare_amounts', lazy='joined')) description = db.Column(db.String(500), nullable=True)
class UserMod(db.Model): __tablename__ = 'user_mod' id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer, db.ForeignKey(User.id)) type = db.Column(db.Enum(*UserModType.choices(), name='user_mod_types')) value = db.Column(JSON, nullable=True) user = db.relationship(User, backref=db.backref('usermods', lazy='joined'))
class Salary(db.Model): __tablename__ = 'salary' id = db.Column(db.Integer, primary_key=True) create_at = db.Column(db.DateTime, default=datetime.datetime.now) amount_id = db.Column(db.Integer, db.ForeignKey(Amount.id)) amount = db.relationship(Amount, foreign_keys=amount_id, backref=db.backref('salary_amounts', lazy='joined')) date_time = db.Column(db.DateTime, default=datetime.datetime.now) exchange_rate_id = db.Column(db.Integer, db.ForeignKey(ExchangeRate.id)) exchange_rate = db.relationship(ExchangeRate, foreign_keys=exchange_rate_id, backref=db.backref( 'exchange_rate_salaries', lazy='joined')) description = db.Column(db.String(500), nullable=True)
class CashFlow(db.Model): __tablename__ = 'cash_flow' id = db.Column(db.Integer, primary_key=True) create_at = db.Column(db.DateTime, default=datetime.datetime.now) name = db.Column(db.String(255)) description = db.Column(db.String(500), nullable=True) amount_id = db.Column(db.Integer, db.ForeignKey(Amount.id)) amount = db.relationship(Amount, backref=db.backref('cash_flow_amounts', lazy='joined'))
class Costs(db.Model): __tablename__ = 'costs' id = db.Column(db.Integer, primary_key=True) create_at = db.Column(db.DateTime, default=datetime.datetime.now) cash_flow_id = db.Column(db.Integer, db.ForeignKey(CashFlow.id)) cash_flow = db.relationship(CashFlow, backref=db.backref('costs_cash_flows', lazy='joined')) name = db.Column(db.String(255)) description = db.Column(db.String(500), nullable=True)
class Bank(db.Model): __tablename__ = 'bank' id = db.Column(db.Integer, primary_key=True) create_at = db.Column(db.DateTime, default=datetime.datetime.now) name = db.Column(db.String(255)) bank_account_id = db.Column(db.Integer, db.ForeignKey(BankAccount.id)) bank_account = db.relationship(BankAccount, backref=db.backref('bank_bank_accounts', lazy='joined')) description = db.Column(db.String(500), nullable=True)
class UserProfile(db.Model): __tablename__ = 'user_profile' id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer, db.ForeignKey(User.id)) phone = db.Column(db.String(17)) user = db.relationship(User, backref=db.backref('user_profile_users', lazy='joined')) def __unicode__(self): return unicode(self.id)
class Amount(db.Model): __tablename__ = 'amount' id = db.Column(db.Integer, primary_key=True) create_at = db.Column(db.DateTime, default=datetime.datetime.now) value = db.Column(db.Numeric(10, 2)) currency = db.Column(db.Enum(*AmountType.choices(), name='amount_types'), default=AmountType.UAH) description = db.Column(db.String(500), nullable=True) user_id = db.Column(db.Integer, db.ForeignKey(User.id)) user = db.relationship(User, backref=db.backref('useramounts', lazy='joined')) def __unicode__(self): return u'{0} {1}'.format(self.value, self.currency)