Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4320958
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:41:26+00:00 2026-05-21T08:41:26+00:00

Hello I seem to be having some problem involving counting in Django. I have

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T08:41:26+00:00Added an answer on May 21, 2026 at 8:41 am

    after

    status_items = models.StorageItem.objects
                         .filter(client=client_id, itemstatushistory__isnull=False)
                         .distinct().count()
    

    status_items will contain the count of items –> an intobject

    using 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:

    {{ status_items.count }}
    

    The template system will call status_items.count() for you. More infos here: rendering-a-context

    EDIT:

    @Shehzad009 : What I am trying to achieve, is to
    count all items that has their latest
    status not destroyed. Because of the
    one to many relationship, and because
    I want to count the latest statuses
    for each item only, it is a bit tricky

    you could define status_items like this:

    #storageItems where itemstatushistory__status != 'Destroyed'
    storage_items = models.StorageItem.objects
                    .filter(client=client_id,
                            itemstatushistory__isnull=False
                            )
                    .distinct()
    
    # list of items with latest status != 'Destroyed'
    status_items = [item for item in storage_items 
                    if item.itemstatushistory_set.latest().description !='Destroyed']
    
    # list of items with latest status not in ['Destroyed', 'Out']
    status_items = [item for item in storage_items
                    if item.itemstatushistory_set.latest().description
                       not in ['Destroyed', 'Out']]
    

    then in the template:

    {# show items with latest status != destroyed  #}
    {% for item in status_items %}
            {{ item }}
    {% endfor %}
    
    {# items with latest status != destroyed count #}
    {{ status_items|length }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i seem to be having a problem with an html list across a
Hello i'm doing a application in php, and i have a list of items
I'm having a problem stopping the 'feed'; the cancel argument doesn't seem to have
I seem to be having an interesting problem only in chrome (not IE, FF).
Hello I seem to be having a problem of using a base template. My
Hello fellow StackOverflowers. I'm have a brain fart right now, and I cannot seem
hello all i am working on a project in which i have a webpage
I seem to be having problems doing some basic parsing of an XML document
As I'm extremely new to java, I seem to have trouble grasping some concepts.
Hej, I have some data shipped out with the app which shall be copied

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.