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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:41:54+00:00 2026-05-15T07:41:54+00:00

So I have a Django app that processes test results, and I’m trying to

  • 0

So I have a Django app that processes test results, and I’m trying to find the median score for a certain assessment. I would think that this would work:

e = Exam.objects.all()
total = e.count()
median = int(round(total / 2))
median_exam = Exam.objects.filter(assessment=assessment.id).order_by('score')[median:1]
median_score = median_exam.score

But it always returns an empty list. I can get the result I want with this:

e = Exam.objects.all()
total = e.count()
median = int(round(total / 2))
exams = Exam.objects.filter(assessment=assessment.id).order_by('score')
median_score = median_exam[median].score

I would just prefer not to have to query the entire set of exams. I thought about just writing a raw MySQL query that looks something like:

SELECT score FROM assess_exam WHERE assessment_id = 5 ORDER BY score LIMIT 690,1

But if possible, I’d like to stay within Django’s ORM. Mostly, it’s just bothering me that I can’t seem to use order_by with a filter and a limit. Any ideas?

  • 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-15T07:41:54+00:00Added an answer on May 15, 2026 at 7:41 am

    Your slice syntax is wrong. The value after the colon is not the count of elements to get, but the index of the end of the slice. Using ‘median’ on its own without a colon, as you do in your second example, would work.

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

Sidebar

Related Questions

I have written a Django app that makes use of Python threading to create
I'm using Google App Engine and Django templates. I have a table that I
I have a django app with four models in it. I realize now that
Other posters have previously said in this forum that when your Django app starts
I have an app that makes use of 'django-registration' a custom built model named
I have a Django app running on Windows (via Apache + mod_wsgi) that's CPU-bound.
I have a Django app that is basically a web front end on a
I have a Django app that uses Haystack . Is it possible to show
I have configured my Django app to run under Apache+FastCGI on Linux (Ubuntu, if
I have a pretty standard django app, and am wondering how to set the

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.