Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import datetime
- from sqlalchemy import ForeignKey from sqlalchemy.orm import relationship
- from flask import current_app as app
- db = app.db
- class UserInfo(db.Model):
- __tablename_ = 'user_info'
- id = db.Column(db.Integer, primary_key=True)
- username = db.Column(db.String(80), unique=True)
- email = db.Column(db.String(80), unique=True)
- password = db.Column(db.String(100), nullable=False)
- posts = relationship('UserPosts', backref='posts')
- def __init__(self, username, email, password):
- self.username = username
- self.email = email
- self.password = password
- def __repr__(self):
- return '{}-{}'.format(self.username, self.e$ class UserPosts(db.Model):
- __tablename__ = 'posts'
- id = db.Column(db.Integer, primary_key=True)
- comments = db.Column(db.Text)
- pub_date = db.Column(db.DateTime)
- user_id = db.Column(db.Integer, ForeignKey('user_info.id'))
- def __init__(self, comments, pub_date):
- self.comments = comments
- if pub_date is None: pub_date = datetime.utcnow()
- self.pub_date = pub_date
- def __repr__(self):
- return '<comments {}'.format(self.comments)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement