[Answer]-Removing the logged in user's name from the list of users in django

1👍

Use RequestContext() while passing context to template. It will add user context parameter , then you can compare it in your template as

{% for likes in forum.likes.all %}
   {% if user != likes.user %} 
                <li><a href="/get/{{likes.user}}">{{likes.get_full_name}}</a></li>
    {%endif%}
{% endfor %}
👤Rohan

0👍

Can you try something like that ?

{% for likes in forum.likes.all %}
    {% if user != likes.user %}
        <li><a href="/get/{{likes.user}}">{{likes.get_full_name}}</a></li>
    {% endif %}
{% endfor %}
👤Kayf

0👍

I had to compare it with fullname, as I was displaying the users full name in the list. So, this was the solution:

        {% for likes in forum.likes.all.reverse %}
            {% if user.get_full_name != likes.get_full_name %}
                <li><a href="/get/{{likes.user}}">{{likes.get_full_name}}</a></li>
            {% endif %}
        {% endfor %}

Hope this will be helpful to someone as it was for me. And thanks for all those who helped me!

👤Robin

Leave a comment