Changing order in which inlines are displayed in Admin

2 views
Skip to first unread message

Joseph Wakeling

unread,
Nov 12, 2009, 3:16:18 PM11/12/09
to Django users
Hello all,

A little query I haven't been able to find an answer to in docs or
through Google.

I've got a little app on my site to create menus -- it's adapted
(updated to latest Django) from the menu app described at rossp.org.

Anyway, here are the classes defined in admin.py:

#######################################
class MenuItemInline(admin.TabularInline):
model = MenuItem
extra = 3

class MenuAdmin(admin.ModelAdmin):
inlines = [MenuItemInline]

admin.site.register(Menu,MenuAdmin)
#######################################

So, each Menu has several inline elements, MenuItems.

Each MenuItem has a class variable 'order' which determines what order
the items will be listed in (lowest=first). But in the admin view,
MenuItems belonging to a menu are listed in the order they were
created. I'd like them to be sorted by MenuItem.order, but can't work
out how: I've tried setting 'ordering' elements in either MenuItem or
MenuItemInline, but it doesn't work.

Can anyone advise?

Thanks & best wishes,

-- Joe

joshuakarjala

unread,
Nov 12, 2009, 3:21:30 PM11/12/09
to Django users
checkout - http://www.djangosnippets.org/snippets/1489/

I have used this in one project successfully - if you want drag'n'drop

Otherwise just add:

class Meta:
ordering = ('order',)


to you model - and the admin should adhere to the "order"
Reply all
Reply to author
Forward
0 new messages