slightly changed user model (sort of fix)

This commit is contained in:
Tobias Kurze
2019-03-22 16:38:42 +01:00
parent 0469b8dbb5
commit ebc34e396d
3 changed files with 9 additions and 1 deletions

BIN
app.db

Binary file not shown.

0
manage.py Normal file → Executable file
View File

View File

@@ -38,7 +38,8 @@ class User(UserMixin, db.Model):
lang = db.Column(db.String(16), index=False, unique=False) lang = db.Column(db.String(16), index=False, unique=False)
timezone = db.Column(db.String(32), index=False, unique=False) timezone = db.Column(db.String(32), index=False, unique=False)
posts = db.relationship('Post', backref='author', lazy='dynamic') posts = db.relationship('Post', backref='author', lazy='dynamic')
example_data_item = db.relationship('ExampleDataItem', backref='owner', lazy='dynamic') example_data_item = db.relationship('ExampleDataItem', backref='owner')
example_data_item_id = db.Column(db.ForeignKey(ExampleDataItem.id))
about_me = db.Column(db.String(140)) about_me = db.Column(db.String(140))
role = db.Column(db.String(64)) role = db.Column(db.String(64))
password = db.Column(db.String(255), nullable=True) password = db.Column(db.String(255), nullable=True)
@@ -58,6 +59,10 @@ class User(UserMixin, db.Model):
backref=db.backref('followers', lazy='dynamic'), backref=db.backref('followers', lazy='dynamic'),
lazy='dynamic') lazy='dynamic')
def __init__(self, email, password):
self.email = email
self.password = sha256_crypt.encrypt(password)
@staticmethod @staticmethod
def get_by_identifier(identifier): def get_by_identifier(identifier):
""" """
@@ -297,6 +302,9 @@ class User(UserMixin, db.Model):
return Post.query.join(followers, (followers.c.followed_id == Post.user_id)).filter( return Post.query.join(followers, (followers.c.followed_id == Post.user_id)).filter(
followers.c.follower_id == self.id).order_by(Post.timestamp.desc()) followers.c.follower_id == self.id).order_by(Post.timestamp.desc())
def to_dict(self):
return dict(id=self.id, email=self.email)
def __repr__(self): def __repr__(self):
return '<User %r>' % self.nickname return '<User %r>' % self.nickname