Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Express the are_friends predicate in a more efficient way.

  • Loading branch information...
commit d47a65c285d2f382bd83d8086f7cb50ded8f6879 1 parent ba44108
@alex alex authored
Showing with 5 additions and 5 deletions.
  1. +5 −5 friends/managers.py
View
10 friends/managers.py
@@ -1,5 +1,6 @@
from django.conf import settings
from django.db import models
+from django.db.models import Q
if "notification" in settings.INSTALLED_APPS:
@@ -18,11 +19,10 @@ def friends_for_user(self, user):
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
+ return self.filter(
+ Q(from_user=user1, to_user=user2) |
+ Q(from_user=user2, to_user=user1)
+ ).count() > 0
def remove(self, user1, user2):
if self.filter(from_user=user1, to_user=user2):
Please sign in to comment.
Something went wrong with that request. Please try again.