La version 5 de Planète Casio. Regroupe le forum, les programmes, les tutoriel, les sprites et tous les autres outils développés par nos soins.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.py 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. from datetime import datetime
  2. from app import db, login
  3. from flask_login import UserMixin
  4. from werkzeug.security import generate_password_hash, check_password_hash
  5. class User(UserMixin, db.Model):
  6. id = db.Column(db.Integer, primary_key=True)
  7. username = db.Column(db.String(64), index=True, unique=True)
  8. email = db.Column(db.String(120), index=True, unique=True)
  9. password_hash = db.Column(db.String(128))
  10. posts = db.relationship('Post', backref='author', lazy='dynamic')
  11. def __repr__(self):
  12. return '<User {}>'.format(self.username)
  13. def set_password(self, password):
  14. self.password_hash = generate_password_hash(password)
  15. def check_password(self, password):
  16. return check_password_hash(self.password_hash, password)
  17. @login.user_loader
  18. def load_user(id):
  19. return User.query.get(int(id))
  20. class Post(db.Model):
  21. id = db.Column(db.Integer, primary_key=True)
  22. body = db.Column(db.String(140))
  23. timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
  24. user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
  25. def __repr__(self):
  26. return '<Post {}>'.format(self.body)