On 3/17/06, dave.l <[EMAIL PROTECTED]> wrote:
> 1) Menu item ordering
>
> class Iconography(meta.Model):
>     description         = meta.CharField(maxlength=255)
>     def __repr__(self):
>         return self.description
>     class META:
>         admin = meta.Admin(
>             ordering = ('description',),
>         )
>
> class Light(meta.Model):
>     window              = meta.ForeignKey(Window, edit_inline=meta.TABULAR)
>     sub_location        = meta.CharField(maxlength=255, core=True)
>     iconography         = meta.ForeignKey(Iconography)
>     class META:
>         admin = meta.Admin()
>
>
> The 'ordering' works as expected when looking at the Iconography table,
> but when viewing a Light, the 'select' widget shows the Iconography's
> in (I guess) ID order. Is it possible to sort this menu?

Yes, that's possible. Do this by setting "ordering" on your
Iconography model in "class META", like so:

    class META:
        ordering = ('description',)
        admin = meta.Admin()

Putting "ordering" in the meta.Admin() designates the ordering to use
on the admin change-list page. Putting "ordering" in "class META"
designates the default ordering to use *everywhere* (even in
get_list() and other database API code, etc.). If meta.Admin() doesn't
define ordering, the changelist will use the "class META" ordering.
Note that I've removed "ordering" from the admin options in the above
example because it'd be redundant.

> 2) Ordering on foreign key field
>
> class Window(meta.Model):
>     building            = meta.ForeignKey(Building, edit_inline=meta.TABULAR)
>     reference           = meta.CharField(maxlength=255, core=True)
>     location            = meta.ForeignKey(Location)
>     def __repr__(self):
>         return "%s / W%s / %s" % (self.get_building().principal_name,
> self.reference, self.get_location())
>     class META:
>         admin = meta.Admin(
>             ordering = ('reference',), # FIXME sort on building name too
>         )
>
> Is it possible to sort this Window table on the principal_name of the
> building referred to and then the Window's own reference (effectively
> sorted on the __repr__ I have written).

It's not possible to sort by a __repr__() or any other Python
function, because the sorting happens at the database level. What you
could do, though, is add a "class META" ordering to your Building
model that's set to ('principal_name',) and set the admin ordering for
Window to ('building',).

Note that you can set "list_display" to give each field its own column
on the change list. For example:

    list_display = ('building', 'reference', 'location')

The advantage here is that each one of those columns will be sortable.

> 3) Linking to another table
>
> class Building(meta.Model):
>     """Building table."""
>     .....
>
> class Window(meta.Model):
>     building            = meta.ForeignKey(Building, edit_inline=meta.TABULAR)
>     ......
>
> class Light(meta.Model):
>     window              = meta.ForeignKey(Window, edit_inline=meta.TABULAR)
>     ......
>
> Opening an entry in the Window table correcly shows all Lights. Opening
> an entry in the Building table correctly shows all Windows, but it does
> not show all the subsequent Lights. In practice I don't want to as
> there are too many, but is it possible to add links in the inline
> Windows to open the relevant Window table?

The edit_inline functionality only works one level deep, so, if I
understand your question correctly, the admin interface can't do that.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com

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