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 9130421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:57:47+00:00 2026-06-17T07:57:47+00:00

I am using Django. I have three different models, with this parent-child layout: Applicant->Application->Review

  • 0

I am using Django. I have three different models, with this parent-child layout:

Applicant->Application->Review

An applicant can have multiple applications which can have multiple reviews.

I’m trying to write a query with first name, last name, application ID, and the number of reviews that are associated with a person, which could be none to several. I have the following query statement:

list = MUSApplicant.objects.values(
'applicant', 'id', 'applicant__first_name',
'applicant__last_name', 'review').filter(department=department).annotate(acount=Count('review'))

which is giving me this SQL:

    SELECT apply_application.applicant_id, 
    apply_application.id, 
    apply_applicant.first_name, 
    apply_applicant.last_name, 
    apply_review.id, 
    COUNT(apply_review.id) AS acount 
    FROM apply_application 
    INNER JOIN apply_applicant 
    ON (apply_application.applicant_id = apply_applicant.id) 
    LEFT OUTER JOIN apply_review 
    ON (apply_application.id = apply_review.applicant_id) 
    WHERE apply_application.department = 'departmentname'
    GROUP BY apply_application.applicant_id, apply_application.id, apply_applicant.first_name, apply_applicant.last_name, apply_review.id

Which is very close, but the result is not correct — I end up with too many rows that aren’t grouped correctly. I only want it to group by apply_review.id, not everything else. How can I keep it from adding all this extra stuff to my GROUP BY statement?

I’ve stared at the docs endlessly to no avail. It’s very hard sometimes to match your exact data model to the few examples on there, in order to learn anything.

EDIT: Here’s the model:

class Review(models.Model):
    reviewer_eid = models.CharField(max_length=20)
    applicant = models.ForeignKey('Application')
    overall_score = models.FloatField()
    category1 = models.FloatField()
    category2 = models.FloatField()
    category3 = models.FloatField()
    comments = models.TextField()
  • 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-06-17T07:57:48+00:00Added an answer on June 17, 2026 at 7:57 am

    I figured it out. I needed Count('review__applicant') instead of Count('review'). I figured out that those extra GROUP BY statements really have no effect, as they are in the SELECT clause as well.

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

Sidebar

Related Questions

I am using django-registration and would like to have a different page for failed
I have a REST API using Django Tastypie. Given the following code The models
I have followed the suggestion in this question as I am using Django, I
I'm rather new to Django and I'm using Django 1.0. I have this: forms.py:
I'm using a Vote model which can be generically linked to several different models
In django models we have option named managed which can be set True or
I am using AWS and I will have different buckets in my application. I
using django 1.4 I have a model with a datetimefield. I imported django.utils.timezone to
I am using Django 1.3 and have the following issue: In the Admin list
I'm using django, and have a static webpage with a GET form, and about

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.