I have a query set in Django template. It has a price column. I want to display only the price of last row. Is there any template filter which will help the cause?
Those who suggust using filter {{ queryset | last }} are not right. You'll get 'Negative indexing is not supported' this way.
So, the only way seems writing custom filter or use an ugly construction like:
{% for obj in queryset %}
    {% if forloop.last %}
        {{ obj.price }}
    {% endif %}
{% endfor %}
UPD: According to Django changelog {{ queryset.last }} will work from 1.6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With