Django admin: can I define fields order?

You can order the fields as you wish using the ModelAdmin.fields option.

class GenreAdmin(admin.ModelAdmin):
    fields = ('title', 'parent')

Building off rbennell's answer I used a slightly different approach using the new get_fields method introduced in Django 1.7. Here I've overridden it (the code would be in the definition of the parent's ModelAdmin) and removed and re-appended the "parent" field to the end of the list, so it will appear on the bottom of the screen. Using .insert(0,'parent') would put it at the front of the list (which should be obvious if you're familiar with python lists).

def get_fields (self, request, obj=None, **kwargs):
    fields = super().get_fields(request, obj, **kwargs)
    fields.remove('parent')
    fields.append('parent') #can also use insert
    return fields

This assumes that your fields are a list, to be honest I'm not sure if that's an okay assumption, but it's worked fine for me so far.

Tags:

Django