Am I missing something or wouldn't
Tours.objects.all().order_by('tours_country.name')
work?
-richard


On 9/24/07, Oleg Korsak <[EMAIL PROTECTED]> wrote:
>
> Hello! I have such models:
>
> class Country(models.Model):
>         name = models.CharField(_('name'), maxlength=32)
>
>         def __unicode__(self):
>                 return self.name
>
>         class Meta:
>                 verbose_name = _('country')
>                 verbose_name_plural = _('countries')
>                 ordering = ('name',)
>
>         class Admin:
>                 pass
>
>
> class Tour(models.Model):
>         id = models.AutoField(primary_key=True)
>         country = models.ForeignKey(Country)
>         name = models.CharField(_('name'),
> maxlength=64,blank=False,null=False)
>         user = models.ForeignKey(User,blank=True,null=True,default=None)
>
>         def __unicode__(self):
>                 return self.name
>
>         class Meta:
>                 verbose_name = _('tour')
>                 verbose_name_plural = _('tours')
>                 ordering = ('name',)
>                 order_with_respect_to = 'country'
>
>         class Admin:
>                 pass
>
> I want to get such result:
> SELECT c.name,t.name FROM tours_tour t, tours_country c WHERE
> t.country_id=c.id ORDER BY c.name;
>
> For now I've wrote such dirty workaround:
>
> Tour.objects.extra(where=['tours_country.id=tours_tour.country_id'],
> tables=['tours_country']).order_by('tours_country.name')
>
> BUT! I don't want to use table names and so on! how can I use django
> model api to do this instead of writing such workarounds? I need to get
> all tours sorted by country name.
>
> Thanks.
>
>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to