Esempio n. 1
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)
    email = db.Column(db.String, unique=True, nullable=False)
    password = db.Column(db.String, nullable=False)
    post = db.relationship('Post', backref='User', lazy=True)

    def __init__(self, name, email, password):
        self.name = name
        self.email = email
        self.password = password

    def __repr__(self):
        return f'User: {self.name}, {self.email}'
Esempio n. 2
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(
        db.String, nullable=False
    )  # nullable = False bu alanin bos ola bilmeyeceyini gosterir.
    email = db.Column(
        db.String, unique=True, nullable=False
    )  # unique = True yeni email'lerin bir defe istifade olunmasini isteyirik.
    password = db.Column(db.String, nullable=False)
    posts = db.relationship('Post', backref='user', lazy=True)

    def __init__(self, name, email, password):
        self.name = name
        self.email = email
        self.password = password

    def __repr__(self):
        return f'User: {self.name}, {self.email}'