class BankAccount(Model): __tablename__ = 'jhi_bank_account' name = db.Column(db.String) balance = db.Column(db.Float) user_id = db.Column(db.Integer, db.ForeignKey('jhi_user.id')) user = db.relationship('User', backref=db.backref('accounts', lazy='dynamic'))
class Operation(Model): __tablename__ = "jhi_operation" date = db.Column(db.DateTime, nullable=False) description = db.Column(db.String) amount = db.Column(db.Float, nullable=False) bank_account_id = db.Column(db.Integer, db.ForeignKey('jhi_bank_account.id')) bank_account = db.relationship('BankAccount', backref=db.backref('operations', lazy='dynamic')) labels = db.relationship('Label', secondary=operation_label_table, backref=db.backref('operations', lazy='dynamic'))
def ReferenceCol(tablename, nullable=False, **kw): return db.Column(db.ForeignKey("%s.id" % tablename), nullable=nullable, **kw)
class SurrogatePK(object): """A mixin that adds a surrogate integer 'primary key' column named ``id`` to any declarative-mapped class.""" id = db.Column(db.Integer, primary_key=True)
class UserAuthority(Model): __tablename__ = 'jhi_authority' name = db.Column("name", db.String(50), primary_key=True)
class User(Model): __tablename__ = 'jhi_user' uid = db.Column(db.Integer, key="id", primary_key=True) login = db.Column( "login", db.String(50), unique=True, nullable=False) # TODO: have a validator regex for login! password = db.Column("password_hash", db.String(60)) first_name = db.Column("first_name", db.String(50)) last_name = db.Column("last_name", db.String(50)) email = db.Column("email", db.String(191)) image_url = db.Column("image_url", db.String(256)) activated = db.Column("activated", db.Boolean) lang_key = db.Column("lang_key", db.String(10)) activation_key = db.Column("activation_key", db.String(20)) reset_key = db.Column("reset_key", db.String(20)) created_by = db.Column("created_by", db.String(50)) created_date = db.Column("created_date", db.DateTime) reset_date = db.Column("reset_date", db.DateTime) last_modified_by = db.Column("last_modified_by", db.String(50)) last_modified_date = db.Column("last_modified_date", db.DateTime) authorities = db.relationship('UserAuthority', secondary=user_authority_table, backref="users") def __init__(self, login, password, first_name, last_name, email, activated=True, lang_key="en-US"): self.login = login self.password = bc.generate_password_hash(password).decode('utf-8') self.first_name = first_name self.last_name = last_name self.email = email self.activated = activated self.lang_key = lang_key self.created_date = datetime.datetime.now() def check_password(self, password): return bc.check_password_hash(self.password, password)
import datetime from sample_app import db, bc from utils.data import Model user_authority_table = db.Table( "jhi_user_authority", db.Column("user_id", db.Integer, db.ForeignKey('jhi_user.id'), nullable=False), db.Column("authority_name", db.String(50), db.ForeignKey('jhi_authority.name'), nullable=False), db.PrimaryKeyConstraint('user_id', 'authority_name')) class User(Model): __tablename__ = 'jhi_user' uid = db.Column(db.Integer, key="id", primary_key=True) login = db.Column( "login", db.String(50), unique=True, nullable=False) # TODO: have a validator regex for login! password = db.Column("password_hash", db.String(60)) first_name = db.Column("first_name", db.String(50)) last_name = db.Column("last_name", db.String(50)) email = db.Column("email", db.String(191)) image_url = db.Column("image_url", db.String(256)) activated = db.Column("activated", db.Boolean)
class Label(Model): __tablename__ = 'jhi_label' label = db.Column(db.String)
user_id = db.Column(db.Integer, db.ForeignKey('jhi_user.id')) user = db.relationship('User', backref=db.backref('accounts', lazy='dynamic')) class Label(Model): __tablename__ = 'jhi_label' label = db.Column(db.String) operation_label_table = db.Table( "jhi_operation_label", db.Column("operation_id", db.Integer, db.ForeignKey('jhi_operation.id'), nullable=False), db.Column("label_id", db.Integer, db.ForeignKey('jhi_label.id'), nullable=False), db.PrimaryKeyConstraint('operation_id', 'label_id')) class Operation(Model): __tablename__ = "jhi_operation" date = db.Column(db.DateTime, nullable=False) description = db.Column(db.String) amount = db.Column(db.Float, nullable=False) bank_account_id = db.Column(db.Integer,