django - How do I display the number of object returned from a query -
i want display number of objects returned query search. have tried
{{ p.count }} , {{ post.count }}
here post_list.html. have read other posts use methods , not work me. know missing something.
{% extends 'posts/base.html' %} {% block content %} <div class="col-sm-6 col-sm-offset-3"> <h1>{{ title }}</h1> <form method="get" action=" "> <input type="text" name="q" placeholder="search" value="{{ request.get.q }}"/> <input type="submit" value=" search"/> </form> <a href="{% url 'posts:create' %}">create</a> {% p in queryset %} <div class="row"> <div class="col-sm-12 "> <!-- col-sm-6 --> <div class="thumbnail"> {% if p.image %} <img src='{{ p.image.url }}' class="img-responsive" /> {% endif %} <!--<img src="..." alt="...">--> <div class="caption"> {% if p.draft %} <h3>staff only: draft</h3> {% if p.publish > today %}<h3>staff only: future post</h3> {% endif %} {% endif %} <h3><a href='{{ p.get_absolute_url}}'>{{p.title}}</a> <small>{{p.publish | timesince }} </small> </h3> {% if p.user.get_full_name %}<p>author: {{ p.user.get_full_name }}</p>{% endif %} <p>{{p.content | truncatechars:30}}</p> <p><a href="{{ p.get_absolute_url}}" class="btn btn-primary" role="button">view</a> {% if user.is_authenticated %} <a href='{% url "posts:update" p.slug %}' class="btn btn-default" role="button">edit</a> <a href='{% url "posts:delete" p.id %}' class="btn btn-danger" role="button">delete</a> {% endif %} </p> </div> </div> </div> <hr> </div> {% endfor %} <div class="pagination"> <span class="step-links"> {% if queryset.has_previous %} <a href="?{{ page_request_var }}={{ queryset.previous_page_number }}{% if request.get.q %}&q={{ request.get.q }}{% endif %}">previous</a> {% endif %} <span class="current"> page {{ queryset.number }} of {{ queryset.paginator.num_pages }}. </span> {% if queryset.has_next %} <a href="?{{ page_request_var }}={{ queryset.next_page_number }}{% if request.get.q %}&q={{ request.get.q }}{% endif %}">next</a> {% endif %} </span> </div> </div> {% endblock content %}
any appreciated. thanks
you cannot count
on single object p
, because there's no count that. queryset has count
method, do:
{{ queryset.count }}
Comments
Post a Comment