Sort django queryset using a Python list
<p>I have a</p>

<pre><code>Model Car(self.Models)
# a bunch of features here
</code></pre>

<p>then in my views.py, I get all the cars and compute a score for them:</p>

<pre><code>allCars = Car.object.all() # so you get [A, B, C, D]
scoreList = someComputation(allCars) # returns [3,1,2,4]
</code></pre>

<p>then in my template I iterate through allCars to display them; using the ordering the query returned with I get primary key ordering, so</p>

<ol>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
</ol>

<p>However I would like to know if there is a way to order the queryset using the list I computed in the view, which would yield</p>

<ol>
<li>B</li>
<li>C</li>
<li>A</li>
<li>D</li>
</ol>

<p>so doing something like</p>

<pre><code>allCars.order_by(scoreList)
</code></pre>