I would like to order a list in a view by foreign key. If I try
ordering how in the
code below my list is ordered by 'person'. And this means that the
list
ist ordered by the ID of the table Person. But I need a list ordered
by 'nameLast'.
Thus I changed ordering 'person' into 'person.nameLast'. But then I
got an error
"Column not found".

Does anybody have an ideia how to order by a foreign key? I spent a
lot of
time for searching any solution. Unfortunatelly without success.


### CODE ###

class Person(models.Model):
    nameLast  = models.CharField ('Nachname', maxlength = 31)
    nameFirst = models.CharField ('Vorname', maxlength = 31)
    address   = models.CharField ('Adresse', maxlength = 63)

    def __str__(self):
        return "%s, %s " % (self.nameLast, self.nameFirst)

    class Admin:
        list_display = ('nameLast', 'nameFirst', 'address')
        fields = (
            ('Personalien',        {'fields': ('nameLast',
'nameFirst', 'address')})
        )


    class Meta:
        ordering = ('nameLast', 'nameFirst', 'location')
        verbose_name        = "Person"
        verbose_name_plural = "Personen"


class Karateka(models.Model):
    person    = models.ForeignKey   (Person, verbose_name = 'Person',
core = True)
    bsc       = models.BooleanField ('BSC')
    comment   = models.TextField    ('Bemerkung', blank = True, null =
True)

    def __str__(self):
        return "%s" % (self.person)

    class Admin:
        list_display = ('person')
        fields = (
            (None,       {'fields': ('person')})
        )

    def name_last(self):
        return "%s" % (self.person.nameLast)

    class Meta:
        ordering                = ('person')
        verbose_name        = 'Karateka'
        verbose_name_plural = 'Karatekas'

### END CODE ###


--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to