Advertisement
Shell_Casing

models.py

Jul 19th, 2018
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. from app import app
  2. from flask_sqlalchemy import SQLAlchemy
  3. from flask_migrate import Migrate
  4.  
  5. from datetime import datetime
  6.  
  7. db = SQLAlchemy(app)
  8. migrate = Migrate(app, db)
  9.  
  10. class User(db.Model):
  11.     id = db.Column(db.Integer, primary_key=True)
  12.     public_id = db.Column(db.String(60), unique=True, nullable=False)
  13.     username = db.Column(db.String(60), unique=True, nullable=False)
  14.     password = db.Column(db.String(60), nullable=False)
  15.     admin = db.Column(db.Boolean)
  16.     todos = db.relationship('Todo', backref='user', lazy=True)
  17.  
  18. class Todo(db.Model):
  19.     id = db.Column(db.Integer, primary_key=True)
  20.     text = db.Column(db.String(60))
  21.     created_on = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
  22.     complete = db.Column(db.Boolean)
  23.     user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
  24.  
  25.     def __repr__(self):
  26.         return f"Todo('{self.text[:15]}', '{self.created_on}')"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement