Esempio n. 1
0
class Vehicle(db.Model):
    __tablename__ = "vehicles"

    id = db.Column(db.Integer, primary_key=True)
    year = db.Column(db.String(5), nullable=False)
    make = db.Column(db.String(50), nullable=False)
    model = db.Column(db.String(50), nullable=False)

    user_id = db.Column(db.Integer, db.ForeignKey("users.id"))
    user = db.relationship("User")

    def __init__(self, year, make, model, user_id):
        self.year = year
        self.make = make
        self.model = model
        self.user_id = user_id

    def save(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    def __repr__(self):
        return "<Vehicle {}>".format(self.model)
Esempio n. 2
0
class News(db.Model):
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    title = db.Column(db.String(50), nullable=False)
    content = db.Column(db.String(99), nullable=False)
    url = db.Column(db.String(99), nullable=False)
    ctime = db.Column(db.String(30), nullable=False)

    # def __str__(self):
    #     return self.username
Esempio n. 3
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(15), nullable=False)
    password = db.Column(db.String(100), nullable=False)
    mobile = db.Column(db.String(11), unique=True)
    email = db.Column(db.String(30), unique=True)
    create_time = db.Column(db.DateTime, default=datetime.now)
    last_login = db.Column(db.DateTime)
    is_active = db.Column(db.Boolean, default=True)
    is_surperuser = db.Column(db.Boolean, default=False)

    def __str__(self):
        return self.username
Esempio n. 4
0
class User(db.Model):
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    password = db.Column(db.String(128), nullable=False)
    email = db.Column(db.String(80), unique=True, nullable=False)

    vehicles = db.relationship("Vehicle", lazy="dynamic")

    def __init__(self, username, password, email):
        self.username = username
        self.password = generate_password_hash(password)
        self.email = email

    def save(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    @classmethod
    def find_by_username(cls, username):
        return cls.query.filter_by(username=username).first()

    @classmethod
    def find_by_id(cls, _id):
        return cls.query.filter_by(id=_id).first()

    @classmethod
    def find_by_email(cls, email):
        return cls.query.filter_by(email=email).first()

    def __repr__(self):
        return "<User {}>".format(self.username)
Esempio n. 5
0
class Maintenance(db.Model):
    id = db.Column(db.Integer, primary_key=True)