예제 #1
0
파일: models.py 프로젝트: Rensykes/Tabster
class Tabs(
        db.Model
):  #inherits from a basic db model provided by sql alchemy and creates a table called Tabs were we will store our tabs objects
    title = db.Column(
        db.String(80), unique=False, nullable=False, primary_key=False
    )  #create a column named title that consist of a String of at most 80characters, that can store two tabs with the same name, the tab must have a title and is not a primary key
    author = db.Column(db.String(80),
                       unique=False,
                       nullable=False,
                       primary_key=False)
    url = db.Column(db.String(200),
                    unique=True,
                    nullable=False,
                    primary_key=True)
    typology = db.Column(db.String(80),
                         unique=False,
                         nullable=False,
                         primary_key=False)
    capo = db.Column(db.Integer,
                     unique=False,
                     nullable=True,
                     primary_key=False)
    tuning = db.Column(db.String(80),
                       unique=False,
                       nullable=True,
                       primary_key=False)

    def __repr__(
            self
    ):  #representation of our book object as a string (like toString)
        return "<Title: {}>".format(self.title)
예제 #2
0
파일: models.py 프로젝트: Rensykes/Tabster
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    password_hash = db.Column(db.String(128))
    posts = db.relationship('Post', backref='author', lazy='dynamic')

    def __repr__(self):
        return '<User {}>'.format(self.username)

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)
예제 #3
0
파일: models.py 프로젝트: Rensykes/Tabster
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    body = db.Column(db.String(140))
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def __repr__(self):
        return '<Post {}>'.format(self.body)