コード例 #1
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200))
    content = db.Column(db.String(300))
    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
コード例 #2
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    title = db.Column(db.String(200))
    content = db.Column(db.String(300))
    Date_created = db.Column(db.DateTime , nullable = False, default = datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable = False)

    def __repr__(self):
        return "The Title is {} and the user is {}".format(self.title,self.user_id)
コード例 #3
0
ファイル: models.py プロジェクト: pachie95/flask-blog-fall-pn
class Post(db.Model):
     id = db.Column(db.Integer, primary_key = True) 
     title = db.Column(db.String(200))
     content = db.Column(db.String(300))
     date_created = db.Column(db.DateTime, nullable = False, default = datetime.utcnow)
     user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable = False) # Because of the relationship based on the user model; we're saying we have a relationship with the Post Class and User Class showing us which post was made by which user. 
     # Relationship between user and post: user can make many posts but a post is associated with only user
     # USER_ID => 1
     # POST_ID: 23 => Created by USER_ID: 1  

     def __repr__(self):
        return "The Title is {} and the user is {}".format(self.title,self.user_id) # Printing something out to the console everytime a new post is created
コード例 #4
0
class User(db.Model,UserMixin):
    id = db.Column(db.Integer, primary_key = True)
    username = db.Column(db.String(150), nullable = False)
    email = db.Column(db.String(150), unique = True, nullable = False)
    password = db.Column(db.String(256), nullable = False)
    post = db.relationship('Post', backref = 'author', lazy = True)
    
    def __init__(self,username,email,password):
        self.username = username
        self.email = email
        self.password = self.set_password(password)

    def __repr__(self):
        return '{} has been created'.format(self.username)

    def set_password(self,password):
        self.pw_hash = generate_password_hash(password)
        return self.pw_hash
コード例 #5
0
ファイル: models.py プロジェクト: pachie95/flask-blog-fall-pn
class User(db.Model,UserMixin):
    id = db.Column(db.Integer, primary_key = True) # main identifier for our user table
    username = db.Column(db.String(150), nullable = False) # Telling our database that this CANNOT be empty when we say nullable = False
    email = db.Column(db.String(150), unique = True, nullable = False) # Telling our database that this has to be different each time when we say unique = True and that this cannot be empty either
    password = db.Column(db.String(256), nullable = False) # Telling our database that this CANNOT be empty when we say nullable = False
    post = db.relationship('Post', backref = 'author', lazy = True) # Connects which user actually creates the specific post

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

    def __repr__(self): 
        return '{} has been created'.format(self.username) # Lets us see what is being created  

    def set_password(self,password):
        self.pw_hash = generate_password_hash(password)
        return self.pw_hash