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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:17:58+00:00 2026-05-13T16:17:58+00:00

(Please let me know if this is completely absurd, that is probably a reason

  • 0

(Please let me know if this is completely absurd, that is probably a reason why I haven’t found anything on this.)

This story has two models Ranking and Artist, Ranking is generically related to Artist (object_id, content_type… the whole shebang).

I have a list of objects returned by Ranking.objects.values_list() ordered by a certain field (in my case score). So obviously, if I want to display a list of artists that were ranked, I’d want them in the same order. I’ve tried different methods, such as .filter(pk__in=list), .in_bulk(list), etc. Tried coercing the result of .values_list() into a tuple too.

They all take my list:

>>> objects = Ranking.objects.filter(<stuff>).order_by('score')
>>> objects_list = objects.values_list('object_id', flat=True)
>>> objects_list
[8, 1, 2, 15, 14, 3, 13, 31, 16, 5, 4, 7, 32, 9, 37]

And return it like so:

>>> Artist.objects.filter(id__in=objects_list).values_list('id', flat=True)
[7, 32, 3, 8, 4, 2, 31, 9, 37, 13, 16, 1, 5, 15, 14]

(I’m just giving the IDs in the second case for sanity’s sake.)

Right now the only way I can get this to work is to create an empty list and loop through the non-values_list() query.

for item in objects:
    ranked_items.append(item.content_object)

This just produces n queries, so I’m wondering if there’s a better way. As shown by the tags, I’m using PostgreSQL.

  • 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-13T16:17:59+00:00Added an answer on May 13, 2026 at 4:17 pm

    This is not caused by Django; your database is returning them in this order since no ordering is specified.

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

Sidebar

Related Questions

(If anything here needs clarification/ more detail please let me know.) I have an
Does GWT has LazyPanel .I can not see it .Please let me know .If
Please excuse the vague title. If anyone has a suggestion, please let me know!
Please let me know what architecture do VoIP applications use, P2P or Client-Server? Thank
Please let me know why there is lot of white space below the page
Can someone please let me know how to get the different segments of the
Please take a look at the html listed below and let me know why
I'd like to get uniform distribution in range [0.0, 1.0) If possible, please let
I need to write test cases for my application. I've chosen NUnit. Please let
Please suggest some good resources to start writing Java Web services.

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.