class Reviews(db.Model): doctors = db.realtionship(Doctors) id = db.Column(db.Integer,primary_key = True) doctor_id = db.Column(db.Integer,db.ForeignKey('doctors.id'),nullable = False) reviews = db.Column(db.Text)
class BlogPost(db.Model): # we set up and reference the relationship between the blog post and a User users = db.relationship(User) # we set up a column for the id of the blog post which is a primary key id = db.Column(db.Integer, primary_key=True) # we set up the user_id which is an integer which is an integer which is a foreign key referencing the id of the # users table user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) # we set it to a date time column with the default set to the present date and time date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) # we set the title to a string of 140 characters which must be filled title = db.Column(db.String(140), nullable=False) # text set to a db text and must be inputted text = db.Column(db.Text, nullable=False) # we then set the title text and userid as a representation attributes of the blog post class def __init__(self, title, text, user_id): self.title = title self.text = text self.user_id = user_id # we then set up a representation of this class which can be used for debugging or testing purposes 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) 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(200), 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) 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 to_json(self): json_post = { 'url': url_for('blog_posts_api.get_post', post_id=self.id), 'date': self.date, 'title': self.title, 'text': self.text, 'author': self.author.username, 'author_url': url_for('users_api.get_user', username=self.author.username) } return json_post @staticmethod def from_json(json_post, user_id): title = json_post.get('title') text = json_post.get('text') if title is None or title == '': raise ValidationError('Post has no title.') if text is None or text == '': raise ValidationError('Post has no text.') return BlogPost(title=title, text=text, user_id=user_id) def __repr__(self): return f"Post ID: {self.id} -- Date: {self.date} -- {self.title}"