On the models of tutorial 1, I want to get a list of Poll, order by  
how many choices it has.

class Poll(models.Model):
     question = models.CharField(maxlength=200)
     pub_date = models.DateTimeField('date published')

class Choice(models.Model):
     poll = models.ForeignKey(Poll)
     choice = models.CharField(maxlength=200)
     votes = models.IntegerField()

I use a custom SELECT column as:
select = {
'choices': 'SELECT COUNT(*) FROM polls_choice WHERE  
poll_id=polls_poll.id',
}
p = Poll.objects.extra(select=select).order_by('choices')

By trying this, I found out a bug in the ORM layer which I reported  
and submitted a patch as:
http://code.djangoproject.com/ticket/1730

Custom SELECT column is one way, I'd like to know is there any other  
ways to get the same thing, esp. only using db api since I try to  
avoid doing custom SQL as much as possible for portability purpose.

BR,
- Cheng


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to