I would like to do the same. But if I try

    class Meta:
        ordering = ['name']

the drop down menu is still ordered by ID and not by name.
Because name is in an other model (foreign key). This is my code:

### 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')         ######### I need
to order by "person.nameLast"
        verbose_name        = 'Karateka'
        verbose_name_plural = 'Karatekas'

### END CODE ###

If I try "ordering = ('person.nameLast')" I get the error "Column not
found".

In templates this problem is resolvable. But how can I get an ordered
drop down list
in the admin interface?

On 27 Okt., 21:23, Griffin Caprio <[EMAIL PROTECTED]> wrote:
> Gustaf,
>
> Awesome thanks.
>
> - Griffin
> On Oct 27, 2007, at 2:15 PM, [EMAIL PROTECTED] wrote:
>
>
>
> > class MyModel(models.Model):
> >     ...
>
> >     class Meta:
> >         ordering = ['name']
>
> > /Gustaf
>
> > On Oct 27, 8:07 pm, Griffin <[EMAIL PROTECTED]> wrote:
> >> Is there any way to customize thedropdownlists that appear when
> >> editing an object in theadmininterface?  I would like to change the
> >>orderthat elements appear.  Instead of sorting by id, I would
> >> like to
> >> sort by another property such as name.
>
> >> I've already customized theAdminclass within the model itself,
> >> but I
> >> can't find any option that allows me to customize how the fields are
> >> displayed.
>
> >> Is the only option a custom view?
>
> >> Thanks,
> >> Griffin


--~--~---------~--~----~------------~-------~--~----~
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