Beispiel #1
0
class Item(DB.Model):
    """Item database model"""
    __tablename__ = 'items'

    id = DB.Column(DB.Integer,
                   nullable=False,
                   autoincrement=True,
                   primary_key=True)
    create_date = DB.Column(DB.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    user_id = DB.Column(DB.Integer,
                        DB.ForeignKey(User.__tablename__ + '.id'),
                        nullable=False)
    location_id = DB.Column(DB.Integer,
                            DB.ForeignKey(Location.__tablename__ + '.id'),
                            nullable=True)
    description = DB.Column(DB.Text, nullable=True)
    name = DB.Column(DB.Text, nullable=False)

    purchase_date = DB.Column(DB.DateTime, nullable=True)
    purchase_price = DB.Column(DB.Numeric(precision=19,
                                          scale=4,
                                          asdecimal=True),
                               nullable=True)
    sell_date = DB.Column(DB.DateTime, nullable=True)
    sell_price = DB.Column(DB.Numeric(precision=19, scale=4, asdecimal=True),
                           nullable=True)
    listed_price = DB.Column(DB.Numeric(precision=19, scale=4, asdecimal=True),
                             nullable=True)

    pictures = DB.relationship("Picture", cascade="all,delete", backref="item")
Beispiel #2
0
class User(DB.Model):
    """User database model"""
    __tablename__ = 'users'

    id = DB.Column(DB.Integer,
                   nullable=False,
                   autoincrement=True,
                   primary_key=True)
    username = DB.Column(DB.String(80), unique=True, nullable=False)
    email = DB.Column(DB.String(120), nullable=False)
    password_hash = DB.Column(DB.String(64), nullable=False)
    create_date = DB.Column(DB.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    items = DB.relationship('Item', backref='user', lazy=True)