Last active
October 9, 2018 20:15
-
-
Save craigderington/21f02b881fd8596cd86b5d69556192ba to your computer and use it in GitHub Desktop.
Celery project models
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from app import db | |
| from datetime import datetime | |
| from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Boolean, Text, Float | |
| from sqlalchemy.orm import relationship | |
| from werkzeug.security import generate_password_hash, check_password_hash | |
| # Define application db.Models | |
| class User(db.Model): | |
| __tablename__ = 'ab_user' | |
| id = Column(Integer, primary_key=True) | |
| first_name = Column(String(64), nullable=False) | |
| last_name = Column(String(64), nullable=False) | |
| username = Column(String(64), unique=True, nullable=False, index=True) | |
| password = Column(String(256), nullable=False) | |
| active = Column(Boolean, default=1) | |
| email = Column(String(120), unique=True, nullable=False) | |
| last_login = Column(DateTime) | |
| login_count = Column(Integer) | |
| fail_login_count = Column(Integer) | |
| created_on = Column(DateTime, default=datetime.now, nullable=True) | |
| changed_on = Column(DateTime, default=datetime.now, nullable=True) | |
| created_by_fk = Column(Integer) | |
| changed_by_fk = Column(Integer) | |
| def __init__(self, username, password): | |
| self.username = username | |
| self.set_password(password) | |
| def set_password(self, password): | |
| self.pw_hash = generate_password_hash(password) | |
| def check_password(self, password): | |
| return check_password_hash(self.pw_hash, password) | |
| def __repr__(self): | |
| if self.last_name and self.first_name: | |
| return '{} {}'.format( | |
| self.first_name, | |
| self.last_name | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment