| AR003 | 147 |
| CH005 | 69 |
| CO001 | 50 |
| CO031 | 50 |
| CH029 | 49 |
| AR004 | None |
| AR029 | None |
| CO217 | None |
| CO024 | 3000 |
| PE017 | 1400 |
| VE025 | 988 |
| CO013 | 930 |
| PE203 | 628 |
| CH016 | 523 |
I'm not sure if both postgresql and sqlite support the coalesce
function, but you might try
contest = Participant.objects.extra(select={
'contest_stats': """
Coalesce((
SELECT SUM(amt)
FROM contest_data
WHERE contest_data.participant_id =
region_participant.id
), 0)
"""
}).order_by('-contest_stats')
(for clarity, that's
Coalesce((SELECT...), 0)
which, if the SELECT returns a null result, should then fall to
the next value passed, i.e. 0.
-tim