Пример #1
0
class Route(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), nullable=False)
    time = db.Column(db.String(60), nullable=False)
    amount = db.Column(db.Integer(), nullable=False)
    availability = db.relationship('Availability', backref='route')
    booking = db.relationship('Booking', backref='route')

    def __repr__(self):
        return f"Route('{self.name}','{self.time}','{self.amount}')"
Пример #2
0
class Buses(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), unique=True, nullable=False)
    number = db.Column(db.String(20), unique=True, nullable=False)
    description = db.Column(db.String(200), nullable=False)
    image_file = db.Column(db.String(60),
                           nullable=False,
                           default='default_bus.jpg')
    bookings = db.relationship('Booking', backref='bus')
    availability = db.relationship('Availability', backref='bus')

    def __repr__(self):
        return f"Bus('{self.name}','{self.number}','{self.description}','{self.image_file}')"
Пример #3
0
class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100))
    email = db.Column(db.String(100))
    password = db.Column(db.String(100))
    token = db.Column(db.String(100))
    threads = db.relationship('Thread', backref='user')
    messages = db.relationship('Message', backref='user')

    def __init__(self, name, email, password, token):
        self.name = name
        self.email = email
        self.password = password
        self.token = token
Пример #4
0
class Seats(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(5), unique=True, nullable=False)
    bookings = db.relationship('Booking', backref='seat')

    def __repr__(self):
        return f"('{self.name}')"
Пример #5
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), unique=True, nullable=False)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    phone = db.Column(db.Integer(), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    active = db.Column(db.Boolean)
    bookings = db.relationship('Booking', backref='customer')
    roles = db.relationship('Role',
                            secondary='roles_users',
                            backref=db.backref('users', lazy='dynamic'))

    def __repr__(self):
        return f"User('{self.name}','{self.username}','{self.email}','{self.phone}','{self.image_file}')"
Пример #6
0
class Thread(db.Model):
    __tablename__ = 'thread'
    id = db.Column(db.Integer, primary_key = True)
    title = db.Column(db.String(100))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    messages = db.relationship('Message', backref = 'thread')

    def __init__(self, title, user_id):
        self.title = title
        self.user_id = user_id
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(140))
    body = db.Column(db.String(256))
    timestamp = db.Column(db.Integer)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    replys = db.relationship('Reply', backref='author', lazy='dynamic')

    def __repr__(self):
        return '<Post %r>' % (self.title)
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    nickname = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    password = db.Column(db.String(120))
    timestamp = db.Column(db.Integer)
    role = db.Column(db.Text)
    posts = db.relationship('Post', backref='author', lazy='dynamic')

    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return str(self.id)  # python 3

    def is_allowed(self):
        if ("Professor" in str(self.role)) or ("Senior" in str(self.role)):
            return True
        else:
            return False

    @lm.user_loader
    def load_user(id):
        return User.query.get(int(id))

    def __repr__(self):
        return json.dumps({
            'id': self.id,
            'nickname': self.nickname,
            'email': self.email,
            'role': self.role
        })