Saturday, August 31, 2013

Re: Removing the logged in user's name from the list of users in django

Ok, I did it by doing this:

            {% 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 %}
Anyways thanks!


On Sat, Aug 31, 2013 at 12:13 AM, C. Kirby <misthop@gmail.com> wrote:
I think you can use "is", but try this:
{% if not likes.user == request.user %}


On Friday, August 30, 2013 12:21:41 PM UTC-5, Robin Lery wrote:

I am getting an error:

TemplateSyntaxError at /forum/

Unused 'is' at end of if expression.


On Fri, Aug 30, 2013 at 10:05 PM, C. Kirby <mis...@gmail.com> wrote:
To remove the current user from your list just use an if statement in your template that tests the user instance you are iterating over against request.user
i.e.

  
{% for likes in forum.likes.all %}
  {% if not likes.user is request.user %}<li><a href="/get/{{likes.user}}">{{likes.get_full_name}}</a></li>{% endif %} {% endfor %}
To reverse the list I think you can do:
  {% for likes in forum.likes.all.reverse %}

On Friday, August 30, 2013 10:35:46 AM UTC-5, Robin Lery wrote:
I have a template that displays the numbers of likes and name of the users liked the forum. But I don't want the request.user's (logged in user's) name in the list, I just want the other user's name and not the user itself. How do I achieve this? And also I want the list of the names in the reverse order in the template (now its showing the latest liked user in the last of the list.). Please guide me. Thank you.Inline image 1

forums.html:

  {% extends "base.html" %}  {% load forum_tags %}    {% block content %}  <h2>Logged in as -- {{request.user}}</h2>  <h1>Forums:</h1>      {% if forums.count > 0 %}          {% for forum in forums %}              <h2><a href="/forum/get/{{forum.id}}/">{{forum.question}}</a></h2>              <p>{{forum.body | truncatewords:"30"}}</p>              {% if user in forum.likes.all and forum.likes.count > 1 %}                  <p><a href="/forum/delete_likes/{{forum.id}}/">Unlike</a> You and {{forum.likes.count | substract:1}} others liked</p>              {% elif user in forum.likes.all %}                  <p>You liked it</p>              {% else %}                  <p><a href="/forum/update_likes/{{forum.id}}/">Like</a></p>              {% endif %}              {% for likes in forum.likes.all %}                  <li><a href="/get/{{likes.user}}">{{likes.get_full_name}}</a></li>              {% endfor %}          {% endfor %}      {% else %}          <p>Sorry! No forum to display.</p>      {% endif %}    {% endblock %}

snippet of views.py:

  def forums(request):      forums = Forum.objects.all()      c = {'forums': forums}      return render(request, 'forums.html', c)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment