Created
April 10, 2013 21:26
-
-
Save robrocker7/5358588 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example friendship | |
class UserProflile(models.Model): | |
''' | |
normal fields | |
''' | |
friends = models.ManyToManyField(UserProfile, related_name='friends', blank=True, null=True) | |
''' | |
methods | |
''' | |
def friend_or_follower(self, user): | |
user_profile = user.get_profile() | |
follow_check = self.friends_set.filter(id=user_profile.id).count() | |
flag = None | |
if follow_check > 0: | |
# self.user is following supplied user_profile = Follower | |
flag = 'follower' | |
# now check to see if the relationship is reciprocated | |
friend_check = user_profile.friends_set.filter(id=self.id).count() | |
if friend_check > 0: | |
# user_profile is following self.user = Friend | |
flag = 'friend' | |
return flag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment