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

  • Home
  • SEARCH
  • 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 648109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:47:47+00:00 2026-05-13T21:47:47+00:00

I have a field for addedBy in one of my classes. I’ve set up

  • 0

I have a field for addedBy in one of my classes. I’ve set up a count for this field as below:

user_count = Issues.objects.values('addedBy').annotate(count=Count('id'))

Then in my template I’m accessing the variable as

{% if user_count %}
   <div class="menutitle"><strong>{% trans "Added By" %}</strong></div>
       {% for item in user_count %}
        <ul>
          <li><a href="#">{{ item.addedBy }} ({{ item.count }})</a> </li>
        </ul>
        {% endfor %}
{% endif %}

But all I get is the ID for the user not the username as intended.

EDIT: Issues Model

class Issues(models.Model):
   ISSUE_CHOICES = (
    ('Mechanical', 'Mechanical'),
    ('Dent', 'Dent'),
    ('Interior', 'Interior'),
    ('Body', 'Body'),
    ('Part', 'Part'),
    ('Other', 'Other'),
   )
   ISSUE_STATUS_CHOICES = (
    ('In Progress', 'In Progress'),
    ('Completed', 'Completed'),
    ('Pending', 'Pending'),
   )

   vehicle = models.ForeignKey(Vehicle)
   description = models.CharField('Issue Description', max_length=30,)
   type = models.CharField(max_length=10, default='Other', choices=ISSUE_CHOICES)
   status = models.CharField(max_length=12, default='Pending', 
     choices=ISSUE_STATUS_CHOICES)
   priority = models.IntegerField(default='8', editable=False)
   addedBy = models.ForeignKey(User, related_name='added_by', editable=False)
   assignedTo = models.ForeignKey(User, related_name='assigned_by', blank=True,
    null=True)
   dateTimeAdded = models.DateTimeField('Added On', default=datetime.today,
    editable=False)
   last_updated = models.DateTimeField(default=datetime.today, 
    editable=False)
   def __unicode__(self):    
      return self.description
   def save(self):
     self.last_updated = datetime.now()
     super(Issues, self).save()
  • 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-13T21:47:47+00:00Added an answer on May 13, 2026 at 9:47 pm

    Try changing the user_count assignment to:

    user_count = Issues.objects.values('addedBy__username').annotate(count=Count('id'))
    

    and on your template:

    <li><a href="#">{{ item.addedBy__username }} ({{ item.count }})</a> </li>
    

    I had a similar issue before and this solved it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code below. It works if i use only ONE WHERE variable
I have field like a_b_c_d I want as the output a b c_d, this
In my class, I have field int count . I want to create a
I'm converting my fields class read functions into one template function. I have field
I have field type string that can get two type of values on it:
How can I have field dependency? Case 1: If boolean field call_me is set,
i have table (MEN) with 900,000 records. in this table i have field IP
I have field in MySQL table which i set it to default value as
I have field string field 'tags' and I want to list all indexed values
i have field with content like this: 1, 2, 100 first two numbers can

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.