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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:29:04+00:00 2026-05-22T23:29:04+00:00

The model structure is Question has one Video, and Question has many Answers. The

  • 0

The model structure is Question has one Video, and Question has many Answers.

The problem query is:

questions = Question.objects\
  .values('id', 'answer', 'section__title', 'title', 'created_at','user__username')\
  .filter(video=v).annotate(answer_count=Count('answer'))

I’m using the Count aggregate function to add an extra field to say how many answers a question has.

It works fine for zero and one answers. But if a question has three answers, I get three different rows back with the same ID, with answer_count=1 and different IDs for the ‘answer’ field.

What am I doing wrong?

  • 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-22T23:29:05+00:00Added an answer on May 22, 2026 at 11:29 pm

    I’m not sure what your model definition is. I assume you have something like this:

    class Answer(models.Models):
        question = models.ForeignKey(Question, related_name='answer')
    

    When you query the way you described, you will retrieve one row per answer. If you leave out 'answer', from the values call, you should get what you wanted.

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

Sidebar

Related Questions

I have an entity model where the base class in an inheritance structure has
This is more of an open question rather than looking for one specific answer.
I've been working with Swing for a while now but the whole model/structure of
I've written a rails app that follows the regular directory structure (model code in
I have the following model structure: class Container(models.Model): pass class Generic(models.Model): name = models.CharacterField(unique=True)
I'm trying to model a site similar to StackOverflow. It has a set of
One of our products implements the following one-way web service structure: Server <--------------------- Middleware
in a simple drawing application I have a model which has a NSMutableArray curvedPaths
In my project jOOQ , I model SQL queries with a complex data structure.
Should the model just be data structures? Where do the services (data access, business

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.