Friday, August 30, 2013

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

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.

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+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