Search code examples
djangodjango-admin

How to position inlines in Django Admin in the list_display property?


I have two tables related Quiz and Difficulty_level:

I have created inline in admin.py like this:

class DifficultyLevelInline(admin.TabularInline):
    model = DifficultyLevel

and included in QuizAdmin

To arrange the list order, I would do:

  list_display = ('name', 'description', 'publication_date', 'category', 'is_active', 'is_premium')

How can I add inlines in the list_display order. I want to display The DifficultyLevelInline before category.


Solution

  • Unfortunately this is not possible using the default template.

    If you take a look at change_form template:

    https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/change_form.html

    You can see that inlines are always rendered after fieldsets.

    One way to get around this would be to use other template:

    class MyAdmin(admin.ModelAdmin):
        list_display = ('name', 'description', 'publication_date', 'category', 'is_active', 'is_premium')
        inlines = (DifficultyLevelInline,)
        change_form_template = "my_change_form.html"