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,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 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): __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 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 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 Todo(db.Model): id = db.Column(db.Integer, primary_key=True) createTime = db.Column(db.DateTime) title = db.Column(db.Text) editTime = db.Column(db.Integer, default=0) def to_json(self): dict = self.__dict__ if "_sa_instance_state" in dict: del dict["_sa_instance_state"] return dict
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 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 Task(db.Model): # Unique ID for a Task, for internal use. id = db.Column(db.Integer, primary_key=True) # The display text for a Task, e.g. "Wash the car." title = db.Column(db.String) # The desired completion date of a Task. target_date = date_created = db.Column(db.Date) # A boolean value to mark a task as complete. active = db.Column(db.Boolean, default=True) # A timestamp representing when a Task was created. Might not use this in practice. date_created = db.Column(db.DateTime, default=datetime.now) @validates('title') def validate_title(self, key, title): """Validates the 'title' value sent to the server by ensuring that the value is not null and not empty.""" if not title or title == '': raise AssertionError('No title was provided.') return title @validates('target_date') def validate_target_date(self, key, target_date): """Validates the 'target_date' value sent to the server by ensuring that the value can be parsed as a valid python date object.""" if not target_date: raise AssertionError('No target date was provided.') try: return datetime.strptime(target_date, '%Y-%m-%d').date() except ValueError: raise AssertionError( 'Could not interpret the target date provided.') def __repr__(self): return 'To-Do Item #{} - "{}" - Created on {}'.format( self.id, self.title, self.date_created )
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 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 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 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 Todo(db.Model): id = db.Column(db.Integer, primary_key=True) item = db.Column(db.String) category = db.Column(db.String)
class TodoItem(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(60)) descs = db.Column(db.String(256))