[Answer]-How do I pass nested context to a Django template? Eg All posts from all users with current_user_likes_post (True or False) for each post

1👍

# views.py
User_likes_ids = UserLikes.objects.filter(user=request.user).values_list('post_id', flat=True)
posts = Post.objects.all()

# template.html
{% for post in posts %}
    {% if post.id in user_likes_ids %}you like this - unlike{% else %}like{% endif %}
{% endfor %}

Leave a comment