Я смог получить список всех пользователей, а также внедрить отправленный запрос в друзья (следующий/последователь). Теперь, как мне получить общие друзья (следующие/подписчики)? Например; Если у обоих пользователей есть общий друг существующий.class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL,on_delete=models.CASCADE,blank=True,null=True)
profile_pic = models.ImageField(upload_to='UploadedProfilePicture/', default="ProfileAvatar/avatar.png", blank=True)
following = models.ManyToManyField(
'Profile', # Refers to the User model itself
symmetrical=False, # If A follows B, B doesn't automatically follow A
related_name='followers', # Reverse relationship: get followers of a user
blank=True,
)
def FollowingView(request):
page_title = "Following"
# All users following posts
posts = Post.objects.filter(
Q(poster_profile=request.user)|
Q(poster_profile__profile__followers__user=request.user)).order_by("?").distinct()
# All account users
profile_users = Profile.objects.exclude(
Q(user=request.user))
# Mutual Followers
all_following = request.user.profile.following.values_list('pk', flat=True)
mutual_followers = Profile.objects.filter(pk__in=all_following)
Подробнее здесь: https://stackoverflow.com/questions/796 ... nds-django
Как получить общие друзья - django ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Какова логика этого решения для задачи C Google Code Jam '16, раунд 1A — лучшие друзья?
Anonymous » » в форуме Python - 0 Ответы
- 39 Просмотры
-
Последнее сообщение Anonymous
-