I have a model where a field can be null (and is most of the time).  
However, I need to order_by this both this field and another field (the 2nd 
field is never null) so that the results would be sorted by from high to 
low (1st based on the possible null field if it is not null and then by the 
2nd field).

Example:

Model 1:
  dollar_amount = Char()
  rating = Int()
  effectual_rating = Int(null=True, blank=True)

Example Entries:
$100, 5, Null
$125, 4, 8
$195, 3, 2
$81, 7, Null

So the end result of the query i would want it sorted like so from high to 
low value:
$125, 4, 8
$81, 7, Null
$100, 5, Null
$195, 3, 2


I have millions of rows so doing multiple queries and then looping through 
those would be not feasible.  But I am not sure how to even start to setup 
this query properly.

Model1.objects.all().order_by(???)

Any help would be appreciated.  Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4e31e3ee-9bc9-4633-923c-6b9f9b836c37%40googlegroups.com.

Reply via email to