@login_required(login_url='/accounts/login/')
def index(request):
    title = 'Moments: Feed'
    current_user = request.user
    current_profile = Profile.objects.filter(user_name=current_user.username).first()
    if current_profile:
        all_posts = list()
        users_posts = Image.objects.filter(profile_id=current_profile).all()
        user_posts_count = users_posts.count()
        folowing_count = len(current_profile.following)
        if (folowing_count >= 0):
            all_following_post = list()
            for item in current_profile.following:
                following_posts = Image.objects.filter(profile_id=item).all()
                all_following_post.append(following_posts)
            all_posts = list(chain(users_posts, all_posts))
        return render(request, 'dashboard.html', {'title': title, 'all_posts': all_posts, 'profile': current_profile, 'post_count': user_posts_count})
    else:
        return redirect('Create Profile')
@login_required(login_url='/accounts/login/')
def index(request):
    title = 'Moments: Feed'
    current_user = request.user
    current_profile = Profile.objects.filter(user_name=current_user.username).first()
    if current_profile:
        all_posts = list()
        users_posts = Image.objects.filter(profile_id=current_profile).all()
        user_posts_count = users_posts.count()
        folowing_count = len(current_profile.following)
        if (folowing_count >= 0):
            all_following_post = list()
            for item in current_profile.following:
                following_posts = Image.objects.filter(profile_id=item).all()
                all_following_post.append(following_posts)
            all_posts = list(chain(users_posts, all_posts))
        return render(request, 'dashboard.html', {'title': title, 'all_posts': all_posts, 'profile': current_profile, 'post_count': user_posts_count})
    else:
        return redirect('Create Profile')