You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

from flask_login import UserMixin
from flask_sqlalchemy import SQLAlchemy
from import check_password_hash, generate_password_hash
db = SQLAlchemy()
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64), unique=True)
password_hash = db.Column(db.String(128), unique=False)
ideas = db.relationship("Idea", backref="user", lazy="dynamic")
def password(self):
raise AttributeError("password is not a readable attribute")
def password(self, password):
self.password_hash = generate_password_hash(password)
def verify_password(self, password):
return check_password_hash(self.password_hash, password)
def __repr__(self):
return "<User %r>" % self.username
class Idea(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(128), unique=False)
description = db.Column(db.Text(), nullable=True)
user_id = db.Column(db.Integer, db.ForeignKey(""))
def __repr__(self):
return "<Idea %r>" %