model objects question

0 views
Skip to first unread message

Oleg Korsak

unread,
Sep 22, 2007, 7:47:08 PM9/22/07
to django...@googlegroups.com
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)
user = models.ForeignKey(User,blank=True,null=True,default=None)

def __unicode__(self):
return self.name

class Meta:
verbose_name = _('tour host')
verbose_name_plural = _('tour hosts')
ordering = ('name',)

class Admin:
pass

----------------
The problem is that I want to build such list (ordered by country name
and then tour name):

Angola Tour1
Angola Tour2
Angola Tour3
Germany Tour1
Germany Tour2
USA Tour1


Right now I have such commands:

tour_paginator = ObjectPaginator(Tour.objects.all(), 20)
tours = tour_paginator.get_page(page - 1)

But they get that list ordered only by tour name:

Angola Tour1
Germany Tour1
USA Tour1
Angola Tour2
Germany Tour2
Angola Tour3

How can I resolve my problem?
Thanks.

signature.asc

Alex Koshelev

unread,
Sep 23, 2007, 2:57:26 AM9/23/07
to Django users
class Country(models.Model):
#...
class Meta:
ordering = ('name','tour',)

On 23 сент, 03:47, Oleg Korsak <kamikaze.is.waiting....@gmail.com>
wrote:

> signature.asc
> 1KЗагрузить

Oleg Korsak

unread,
Sep 23, 2007, 5:39:59 PM9/23/07
to django...@googlegroups.com
but Country class doesn't have such field 'tour' ! ;/

Alex Koshelev пишет:

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

signature.asc
Reply all
Reply to author
Forward
0 new messages