all_following_of_10_following = UserFollowing.objects.filter(user__in=random_following_id_list).exclude(following_user= request.user).values_list(
"following_user", flat=True).order_by('?')
final_list = []
#then we see if a user appears more than once in the list and if they do we get that user and add them to a final suggestion qs
cnt = Counter(all_following_of_10_following)
for k, v in cnt.items():
if (v > 1) and not (UserFollowing.objects.filter(user = request.user, following_user__id = k ).exists()) :
final_list.append(k)
follow model:
class UserFollowing(models.Model):
user = models.ForeignKey(
User,
related_name="following",
on_delete=models.CASCADE
)
following_user = models.ForeignKey(
User,
related_name="followers",
on_delete=models.CASCADE
)
created = models.DateTimeField(auto_now_add=True)
currently:
I am getting a list of all the people random 10 users follow and adding it to a list. if a name appears in that list I added it to the final_list
what I would want to do:
- remove the counting, there is no need to count over 2
- omit the counting part and do it using annotate and gt
- if I can, also get the people who follow that particular person that has been added to this list.