Ejemplo n.º 1
0
class Role(db.Model, RoleMixin):
    __tablename__ = 'role'
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.String(255))

    def __repr__(self):
        return "<Role {0}>".format(self.name)
Ejemplo n.º 2
0
class Shop(db.Model):
    __tablename__ = 'shop'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, index=True)
    address = db.Column(db.String)
    latitude = db.Column(db.Float)
    longitude = db.Column(db.Float)
    url = db.Column(URLType)
    photo = db.Column(db.String)  # store the URL location of uploaded photos, or perhaps just the filename.
    date_added = db.Column(db.DateTime, default=datetime.utcnow)

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    user = db.relationship(User, backref=db.backref('shops'))

    def __repr__(self):
        return f'<Shop name={self.name} address={self.address} location=POINT ({self.longitude} {self.latitude}) url={self.url} photo={self.photo} user={self.user_id}>'
Ejemplo n.º 3
0
class Review(db.Model):
    __tablename__ = 'review'

    SCORES = [
        (0, 'Bad'),
        (1, 'Good')
    ]

    id = db.Column(db.Integer, primary_key=True)
    rating = db.Column(db.Integer, nullable=False)
    comment = db.Column(db.String)
    date_added = db.Column(db.DateTime, default=datetime.utcnow)

    shop_id = db.Column(db.Integer, db.ForeignKey('shop.id'), nullable=False)
    shop = db.relationship(Shop, backref=db.backref('reviews', lazy='joined'))

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    user = db.relationship(User, backref=db.backref('reviews'), lazy='joined')

    def __repr__(self):
        return f'<Review rating={self.rating} shop={self.shop_id} user={self.user_id}>'
Ejemplo n.º 4
0
class RolesUsers(db.Model):
    __tablename__ = 'roles_users'
    id = db.Column(db.Integer(), primary_key=True)
    user_id = db.Column('user_id', db.Integer(), db.ForeignKey('user.id'))
    role_id = db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))
Ejemplo n.º 5
0
class User(db.Model, UserMixin):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(255), unique=True)
    screen_name = db.Column(db.String(255))
    password = db.Column(db.String(255))
    last_login_at = db.Column(db.DateTime())
    current_login_at = db.Column(db.DateTime())
    last_login_ip = db.Column(db.String(100))
    current_login_ip = db.Column(db.String(100))
    login_count = db.Column(db.Integer)
    active = db.Column(db.Boolean())
    confirmed_at = db.Column(db.DateTime())
    roles = db.relationship('Role', secondary='roles_users',
                         backref=db.backref('users', lazy='dynamic'))

    def __repr__(self):
        return "<User {0}>".format(self.email)