class BlogPost(db.Model): # Setup the relationship to the User table users = db.relationship(User) # Model for the Blog Posts on Website id = db.Column(db.Integer, primary_key=True) # Notice how we connect the BlogPost to a particular author user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) title = db.Column(db.String(140), nullable=False) text = db.Column(db.Text, nullable=False) category = db.Column(db.String(140), nullable=False, default='news') blog_image = db.Column(db.String(20), nullable=False, default='c1.jpg') blog_thumbnail = db.Column(db.String(20), nullable=False, default='stories1.jpg') def __init__(self, title, text, category, user_id, blog_image, blog_thumbnail): self.title = title self.text = text self.user_id = user_id self.category = category self.blog_image = blog_image self.blog_thumbnail = blog_thumbnail def __repr__(self): return f"Post Id: {self.id} --- Date: {self.date} --- Title: {self.title}"
class BlogPost(db.Model): # Связь позволяющая обращаться к атрибутам МОДЕЛИ Родительской-Связи из МОДЕЛИ Дочерней-Связи, так же просто как это делает МОДЕЛЬ Ролительской-Связи # обращаясь к атрибутам МОДЕЛИ Дочерней-Связи users = db.relationship(User) id = db.Column(db.Integer,primary_key= True) # Дата публикации date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) # Заголовок Публикации title = db.Column(db.String(140),nullable=False) # Текст Публикации text = db.Column(db.Text,nullable=False) # ДОЧЕРНЯЯ МОДЕЛЬ её атрибуты передаются по запросу от атрибута РОДИТЕЛЬСКОЙ МОДЕЛИ(без РОДИТЕЛЬСКОЙ не создать) user_id = db.Column(db.Integer,db.ForeignKey('users.id'), nullable=False) # Конструктор. данные приходящие извне ( дата к ним не относится) def __init__(self,title,text,user_id): self.title = title self.text = text self.user_id = user_id def __repr__(self): return f'Post id: {sefl.id} --- Date: {self.date} --- Title: {self.title}'
class BlogPost(db.Model): #each blogpost is connected to the user users = db.relationship(User) id = db.Column(db.Integer, primary_key=True) #attribute that connects blogpost to user, (nullable)-every blogpost must be associated to user id user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) #tablename: users, attribute: id #every blogpost has to have a publish date date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) #each blogpost has a title, (nullable)-must provide title title = db.Column(db.String(140), nullable=False) text = db.Column(db.Text, nullable=False) #make instance of blogpost def __init__(self, title, text, user_id): self.title = title self.text = text self.user_id = user_id def __repr__(self): return f"Post ID: {self.id} -- Date: {self.date} -- {self.title}"
class BlogPost(db.Model): users = db.relationship(User) id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) title = db.Column(db.String(140), nullable=False) text = db.Column(db.Text, nullable=False) def __init__(self, title, text, user_id): self.title = title self.text = text self.user_id = user_id def __repr__(self): return f"Post ID: {self.id} -- Date: {self.date} -- {self.title}"
class BlogPost(db.Model): users = db.relationship(User) id = db.Column(db.Integer, primary_key=True) user_id = db.Column( db.Integer, db.ForeignKey('users.id'), nullable=False ) ### db.ForeignKey('users.id') in this *users* is the table name above and the id is the attribute of the users table which is getting to create the relationship date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) title = db.Column(db.String(64), nullable=False) text = db.Column(db.Text, nullable=False) def __init__(self, title, text, user_id): self.title = title self.text = text self.user_id = user_id def __repr__(self): return f"Post ID: {self.id} -- Date: {self.date} --- {self.title}"
class BlogPost(db.Model): users = db.relationship(User) __tablename__ = 'blogposts' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(128), nullable=False) text = db.Column(db.String(128), nullable=False) date = db.Column(db.DateTime, default=datetime.utcnow, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) def __init__(self, title, text, user_id): self.title = title self.text = text self.user_id = user_id
class BlogPost(db.Model): # Setup the relationship to the User table users = db.relationship(User) # Model for the Blog Posts on Website id = db.Column(db.Integer, primary_key=True) # Notice how we connect the BlogPost to a particular author user_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False) date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) title = db.Column(db.String(140), nullable=False) text = db.Column(db.Text, nullable=False) # Constructor def __init__(self, title, text, user_id): self.title = title self.text = text self.user_id = user_id # Repr def __repr__(self): return f"Post Id: {self.id} --- Date: {self.date} --- Title: {self.title}"
class BlogPost(db.Model): # get User object users = db.relationship(User) id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) date = db.Column(db.DateTime, nullable=False, default=datetime.now(pytz.timezone('Asia/Tokyo'))) title = db.Column(db.String(140), nullable=False) text = db.Column(db.Text, nullable=False) # profile_image = db.Column(db.String(64), nullable=False,default='default_profile.png') def __init__(self, title, text, user_id): self.title = title self.text = text self.user_id = user_id def __repr__(self): return f"Post ID: {self.id} -- Date: {self.date} -- {self.title}"
class BlogPost(db.Model): # This is used in the ForeignKey lines below users = db.relationship(User) id = db.Column(db.Integer, primary_key=True) # This is what connects the user to the blog post # one to many - one user can have many blog posts user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) title = db.Column(db.String(140), nullable=False) text = db.Column(db.Text, nullable=False) def __init__(self, title, text, user_id): self.title = title self.text = text self.user_id = user_id def __repr__(self): return f"Post id {self.id} -- Date: {self.date} -- Title: {self.title}"