Create the Profile.follow() method

This commit is contained in:
2018-07-11 16:40:42 +02:00
parent 37e08fed22
commit 27c78ff36f
3 changed files with 96 additions and 3 deletions

View File

@@ -317,6 +317,23 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods
return NotImplemented
def follow(self, follower):
"""Make ``follower`` follow this profile
"""
if not isinstance(follower, Profile):
raise TypeError('Folloer must be a Profile object')
user_follow = UserFollow(follower=follower, followed=self, accepted_at=datetime.utcnow())
db.session.add(user_follow)
notification = Notification(profile=self,
actor=follower,
item=self,
action=NotificationAction.follow)
db.session.add(notification)
return user_follow
class Event(db.Model):
"""Database model for events