SHARE
TWEET

Untitled

a guest Jul 19th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def friends(self, user, limit_to=1):
  2.     profile = user.profile
  3.     following = profile.following.all()
  4.     following = profile.get_following()
  5.     qs = self.get_queryset().order_by("?").filter(user__in=following).distinct().exclude(id=profile.id)[:1]
  6.     return qs
  7.      
  8. def toggle_follow(self, user, to_toggle_user):
  9.     user_profile, created = UserProfile.objects.get_or_create(user=user) # (user_obj, true)
  10.     if to_toggle_user in user_profile.following.all():
  11.         user_profile.following.remove(to_toggle_user)
  12.         added = False
  13.     else:
  14.         user_profile.following.add(to_toggle_user)
  15.         added = True
  16.     return added
  17.  
  18.  
  19.  
  20.     def is_following(self, user, followed_by_user):
  21.     user_profile, created = UserProfile.objects.get_or_create(user=user)
  22.     if created:
  23.         return False
  24.     if followed_by_user in user_profile.following.all():
  25.         return True
  26.     return False
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top