Advertisement
Guest User

Untitled

a guest
Oct 14th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. from datetime import datetime
  2. from sqlalchemy import ForeignKey from sqlalchemy.orm import relationship
  3. from flask import current_app as app
  4.  
  5. db = app.db
  6. class UserInfo(db.Model):
  7.  
  8. __tablename_ = 'user_info'
  9. id = db.Column(db.Integer, primary_key=True)
  10. username = db.Column(db.String(80), unique=True)
  11. email = db.Column(db.String(80), unique=True)
  12. password = db.Column(db.String(100), nullable=False)
  13. posts = relationship('UserPosts', backref='posts')
  14. def __init__(self, username, email, password):
  15. self.username = username
  16. self.email = email
  17. self.password = password
  18.  
  19. def __repr__(self):
  20. return '{}-{}'.format(self.username, self.e$ class UserPosts(db.Model):
  21.  
  22. __tablename__ = 'posts'
  23. id = db.Column(db.Integer, primary_key=True)
  24. comments = db.Column(db.Text)
  25. pub_date = db.Column(db.DateTime)
  26. user_id = db.Column(db.Integer, ForeignKey('user_info.id'))
  27.  
  28. def __init__(self, comments, pub_date):
  29. self.comments = comments
  30. if pub_date is None: pub_date = datetime.utcnow()
  31. self.pub_date = pub_date
  32.  
  33. def __repr__(self):
  34. return '<comments {}'.format(self.comments)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement