3

I have list1 in order by id. Like this:

['4','2','1','17'] #edited

How to get list2 from object Entry in order of list1.

In the case Query ValueList, as well as on the question.

[u'4', u'2', u'1', u'17']

Because some properties are not in QuerySet

Thanks for your answers !

2
  • Is list1 in a random order or is there some pattern? Because in your example, the IDs are sorted in descending order. Commented Mar 2, 2010 at 16:54
  • list1 is in random order Commented Mar 2, 2010 at 17:04

2 Answers 2

3

Also you can use in_bulk() and then just get dict values in defined order. Wrap this in custom manager for further comfort

Sign up to request clarification or add additional context in comments.

Comments

1

You'll need to use CASE ... WHEN ... THEN ... END in order to sort your IDs. Pass the full CASE clause in the select argument of extra(), and the use the order_by argument with the given field name.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.