That's a good point. Thanks Jeff. The reason they are none, or have a null value, is because there are actually no related records in the related table.
Two Tables: Participants (contains all potential participants) Data (contains actual participant activity) If there is a way to convert those nulls to zeroes, that would work perfectly. Here's my query, (I'm using the stable release version of django, otherwise I'd use "annotate" which I found is present in the development version). contest = Participant.objects.extra(select={ 'contest_stats': """ SELECT SUM(amt) FROM contest_data WHERE contest_data.participant_id = region_participant.id """ }).order_by('-contest_stats') Thanks, J On Jun 30, 9:28 am, Jeff FW <jeff...@gmail.com> wrote: > Any reason not to make the total 0 instead of None? Null in database > (or None in Python) has a special meaning, and it doesn't always make > sense to sort a list of (mostly) integers with some null values. > > -Jeff > > On Jun 30, 2:01 am, J <jobce...@gmail.com> wrote: > > > Hello, > > > I developed an app for an online contest. > > > In this app, I requested a queryset with totals from a related table, > > and wanted to display the top ten participants. So, I sorted the > > queryset on the totals field, descending. Some participants didn't have > > any items, so the total for these was "None". > > > When using sqlite, this appeared as I wanted, with the objects having > > "None" at the bottom, and thus not included in the top ten. > > > However, after uploading this app to the production site, which has a > > postgres db, the None participants appeared at the top of the list (!), > > and THEN came the largest items successively decreasing as expected. My > > top-ten program failed. > > > Any ideas? > > > Thanks, > > J > > > PS: Examples: > > > Developement, sqlite, working: > > AR003 147 > > CH005 69 > > CO001 50 > > CO031 50 > > CH029 49 > > AR004 None > > AR029 None > > > Production, postgres, not working: > > CO217 None > > CO024 3000 > > PE017 1400 > > VE025 988 > > CO013 930 > > PE203 628 > > CH016 523 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---