From 2738c5d84c26e22ea520fd9f118ee130ddcab7a2 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Thu, 12 Jul 2018 15:07:26 +0200 Subject: [PATCH] WIP: Add Profile.friend_list --- calsocial/models.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/calsocial/models.py b/calsocial/models.py index 9ac6220..c937857 100644 --- a/calsocial/models.py +++ b/calsocial/models.py @@ -310,6 +310,21 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods .filter(UserFollow.followed == self) \ .filter(UserFollow.accepted_at.isnot(None)) + @property + def friend_list(self): + """List of friends (ie. where both profiles follow each other) + """ + + # This will always be empty for remote profiles + if not self.user: + return [] + + reverse = db.aliased(UserFollow) + return UserFollow.query \ + .filter(UserFollow.follower == self) \ + .join(reverse, UserFollow.followed == reverse.follower) \ + .filter(UserFollow.follower == reverse.followed) + @property def url(self): """Get the URL for this profile