Hello I seem to be having some problem involving counting in Django. I have a list of items which only displays its latest status. All of these items that has a status “Destroyed” have been removed. This prints nicely.
status_items = models.StorageItem.objects.filter(client=client_id, itemstatushistory__isnull=False).distinct()
{% for item in status_items %}
{{item.itemstatushistory_set.latest|cut:"Destroyed"}}
{% endfor %}
But I can’t count for some reason.
status_items = models.StorageItem.objects.filter(client=client_id, itemstatushistory__isnull=False).distinct().count()
TypeError while rendering: 'int' object is not iterable
after
status_itemswill contain the count of items –> anintobjectusing it in the template in
{% for item in status_items %}will obviously generate an error.you can leave it without the
count()and in the template access to the count like this:The template system will call
status_items.count()for you. More infos here: rendering-a-contextEDIT:
you could define
status_itemslike this:then in the template: