Permalink
Browse files

Added forgotten managers.py file from previous commit

  • Loading branch information...
1 parent 9f6e1b2 commit f2e4367f068831f3228a397e39a77aa6ed07c3cc @alex alex committed Oct 20, 2009
Showing with 31 additions and 0 deletions.
  1. +31 −0 friends/managers.py
View
@@ -0,0 +1,31 @@
+from django.db import models
+
+
+class FriendshipManager(models.Manager):
+ def friends_for_user(self, user):
+ friends = []
+ for friendship in self.filter(from_user=user).select_related(depth=1):
+ friends.append({"friend": friendship.to_user, "friendship": friendship})
+ for friendship in self.filter(to_user=user).select_related(depth=1):
+ friends.append({"friend": friendship.from_user, "friendship": friendship})
+ return friends
+
+ def are_friends(self, user1, user2):
+ if self.filter(from_user=user1, to_user=user2).count() > 0:
+ return True
+ if self.filter(from_user=user2, to_user=user1).count() > 0:
+ return True
+ return False
+
+ def remove(self, user1, user2):
+ if self.filter(from_user=user1, to_user=user2):
+ friendship = self.filter(from_user=user1, to_user=user2)
+ elif self.filter(from_user=user2, to_user=user1):
+ friendship = self.filter(from_user=user2, to_user=user1)
+ friendship.delete()
+
+
+class FriendshipInvitationManager(models.Manager):
+ def invitations(self, *args, **kwargs):
+ return self.filter(*args, **kwargs).exclude(status__in=["6", "8"])
+

0 comments on commit f2e4367

Please sign in to comment.