class User(UserMixin, db.Model): id = db.Column(db.Integer(), primary_key=True) username = db.Column(db.String(50), nullable=False, unique=True) email= db.Column(db.String(100), nullable=False, unique=True) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password_hash = db.Column(db.String(128)) about_me = db.Column(db.String(140)) last_seen = db.Column(db.DateTime, default=datetime.utcnow) todo = db.relationship("Todo", backref="user", lazy=True) def __repr__(self): return "<{}:{}>".format(self.id, self.username, self.image_file) def set_password(self, password): self.password_hash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password_hash, password) def get_reset_token(self, expires_sec=1800): s = Serializer(current_app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = Serializer(current_app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')"
class User(db.Model,UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(24)) password_hash = db.Column(db.String(128)) todolists = db.relationship('Todolist',back_populates='user',lazy='dynamic') @property def password(self): """ 密码属性不可被访问 """ raise AttributeError('密码不可访问') @password.setter def password(self,password): """ 密码属性可写不可读 :param password: 用户密码 """ self.password_hash = generate_password_hash(password) def verify_password(self, password): """ 密码验证 :param password: 用户密码 :return: 验证成功返回 True,反之返回 False """ return check_password_hash(self.password_hash,password)
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default="default.jpg") password = db.Column(db.String(60), nullable=False) tasks = db.relationship('Task', backref="owner", lazy=True) posts = db.relationship('Post', backref='author', lazy=True) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')" def get_reset_token(self, expires_sec=1800): s = Serializer(current_app.config["SECRET_KEY"], expires_sec) return s.dumps({"user_id": self.id}).decode("utf-8") @staticmethod def verify_reset_token(token): s = s = Serializer(current_app.config["SECRET_KEY"]) try: user_id = s.loads(token)["user_id"] except: return None return User.query.get(user_id)
class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20)) password_hash = db.Column(db.String(128)) def set_password(self, password): self.password_hash = generate_password_hash(password) def validate_password(self, password): return check_password_hash(self.password_hash, password)
class ToDoItem(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80), unique=False, nullable=False) task = db.Column(db.String(120), unique=True, nullable=False) content = db.Column(db.Text, nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) def __repr__(self): return '<User %r>' % self.name
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) subtitle = db.Column(db.String(500), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) post_image = db.Column(db.String(20), nullable=False, default="newdefaultimage.jpg") user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Post('{self.title}', '{self.date_posted}', '{self.post_image}')"
class Todolist(db.Model): id = db.Column(db.Integer,primary_key=True) title = db.Column(db.String(100)) status = db.Column(db.Integer) create_time = db.Column(db.DateTime,default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User',back_populates='todolists')
class Project(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(200), nullable=False) tasks = db.relationship('Task', backref='project', lazy=True) def __repr__(self): return f'Project(id={self.id}, name={self.name})'
class Todo(db.Model): id = db.Column(db.Integer, primary_key=True) text = db.Column(db.String(140)) complete = db.Column(db.Boolean) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return "<{}:{}>".format(self.id, self.text)
class ToDo(db.Model): __tablename__ = "todo" id = db.Column(db.Integer, primary_key=True) content = db.Column(db.String(100), nullable=False) date_created = db.Column(db.DateTime, default=datetime.today) def __repr__(self): return '<Task %r>' % self.id
class Task(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(200), nullable=False) status = db.Column(db.Boolean, nullable=False, default=False) priority = db.Column(db.Integer, nullable=False) deadline = db.Column(db.DateTime, nullable=True) project_id = db.Column(db.Integer, db.ForeignKey('project.id')) def __repr__(self): return f'Task(id={self.id}, ' \ f'name={self.name}, status={self.status}, priority={self.priority}, deadline={self.deadline})'
class Task(db.Model): id = db.Column(db.Integer, primary_key=True) item = db.Column(db.String(200), nullable=False) category = db.Column(db.String(20), nullable=False) start_date = db.Column(db.Date, nullable=False) end_date = db.Column( db.Date, nullable=False, ) complete = db.Column(db.Boolean, nullable=False, unique=False, default=False) date_created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow()) actual_completion_date = db.Column(db.Date) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Task('{self.item}', '{self.category}', '{self.start_date}', '{self.end_date}', '{self.complete}')"
class Entry(db.Model): username = db.Column(db.String(20), unique=True, nullable=False) what_to_do = db.Column(db.String(40), unique=True, nullable=False) due_date = db.Column(db.String(60), nullable=False)
class User(db.Model): username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(40), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False)
class TodoItem(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(60)) descs = db.Column(db.String(256))