in core/views.py [0:0]
def index(request):
user_object = User.objects.get(username=request.user.username)
user_profile = ProfileGCP.objects.get(user=user_object)
user_following_list = []
feed = []
user_following = FollowersCount.objects.filter(follower=request.user.username)
for users in user_following:
user_following_list.append(users.user)
for usernames in user_following_list:
feed_lists = PostGCP.objects.filter(user=usernames)
feed.append(feed_lists)
feed_list = list(chain(*feed))
# user suggestion starts
all_users = User.objects.all()
user_following_all = []
for user in user_following:
user_list = User.objects.get(username=user.user)
user_following_all.append(user_list)
new_suggestions_list = [x for x in list(all_users) if (x not in list(user_following_all))]
current_user = User.objects.filter(username=request.user.username)
final_suggestions_list = [x for x in list(new_suggestions_list) if ( x not in list(current_user))]
random.shuffle(final_suggestions_list)
username_profile = []
username_profile_list = []
for users in final_suggestions_list:
username_profile.append(users.id)
for ids in username_profile:
profile_lists = Profile.objects.filter(id_user=ids)
username_profile_list.append(profile_lists)
suggestions_username_profile_list = list(chain(*username_profile_list))
return render(request, 'index.html', {'user_profile': user_profile, 'posts':feed_list, 'suggestions_username_profile_list': suggestions_username_profile_list[:4]})