Display following/followed users on the profile page
This commit is contained in:
		| @@ -194,6 +194,32 @@ class Profile(db.Model):  # pylint: disable=too-few-public-methods | ||||
|  | ||||
|         return f'<Profile {self.id}(@{username}{domain})>' | ||||
|  | ||||
|     @property | ||||
|     def followed_list(self): | ||||
|         """List of profiles this profile is following | ||||
|         """ | ||||
|  | ||||
|         # This will always be empty for remote profiles | ||||
|         if not self.user: | ||||
|             return [] | ||||
|  | ||||
|         return Profile.query \ | ||||
|             .join(UserFollow.followed) \ | ||||
|             .filter(UserFollow.follower == self) | ||||
|  | ||||
|     @property | ||||
|     def follower_list(self): | ||||
|         """List of profiles that follow this profile | ||||
|         """ | ||||
|  | ||||
|         # This will always be empty for remote profiles | ||||
|         if not self.user: | ||||
|             return [] | ||||
|  | ||||
|         return Profile.query \ | ||||
|             .join(UserFollow.follower) \ | ||||
|             .filter(UserFollow.followed == self) | ||||
|  | ||||
|  | ||||
| class Event(db.Model): | ||||
|     """Database model for events | ||||
| @@ -404,9 +430,13 @@ class UserFollow(db.Model): | ||||
|     #: The ID of the profile that is following the other | ||||
|     follower_id = db.Column(db.Integer(), db.ForeignKey('profiles.id'), primary_key=True) | ||||
|  | ||||
|     follower = db.relationship('Profile', foreign_keys=[follower_id]) | ||||
|  | ||||
|     #: The ID of the profile being followed | ||||
|     followed_id = db.Column(db.Integer(), db.ForeignKey('profiles.id'), primary_key=True) | ||||
|  | ||||
|     followed = db.relationship('Profile', foreign_keys=[followed_id]) | ||||
|  | ||||
|     #: The timestamp when the follow was initiated | ||||
|     initiated_at = db.Column(db.DateTime(), default=datetime.utcnow, nullable=False) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user