class Friend(models.Model):
users = models.ManyToManyField(User)
current_user = models.ForeignKey(User, related_name='owner', null=True)
@classmethod
def who_added_user(cls, user):
users = []
for friend in cls.objects.all():
if user in friend.users.all():
users.append(friend.current_user)
return users
Last active
October 16, 2018 22:41
-
-
Save maxg203/93436252327b32f354fd2239e887ae63 to your computer and use it in GitHub Desktop.
Find the corresponding users that added a given user as a friend.
Thank you @MarcJoan for correction and the feedback! I've updated the original.
If I remember correctly I wrote that snippet off the top of my head so please forgive my recklessness.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, i really apreciate your work ;)