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 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

Ask A Question

Stats

  • Questions 294k
  • Answers 294k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If I understand your code correctly, replace your whole function… May 13, 2026 at 6:34 pm
  • Editorial Team
    Editorial Team added an answer On Posix platforms, multiprocessing primitives essentially wrap an os.fork(). What… May 13, 2026 at 6:34 pm
  • Editorial Team
    Editorial Team added an answer Do you have a JDK installed? You likely want to… May 13, 2026 at 6:34 pm

Related Questions

I'm working with a small (4 person) development team on a C# project. I've
I have installed Eclipse and CDT (to use C/C++ in eclipse CDT is needed),
I would like to know how to benchmark a php/mysql site. We have a
so I upgraded to python 3.1.1 from 2.6 and i ran an old program
I have a JApplet which I contains various Swing components. It also starts a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.