A Django Admin extension that allows you to mix and reorder multiple inline classes together
Merged Inlines is a Django App that allows you to merge multiple inline models into a single form. This is particularly useful if you need to mix the orderings of multiple authors together, so your inlines in the Admin panel can look like:
Install using pip:
pip install django-merged-inlines
INSTALLED_APPS = ( .... 'merged_inlines' )
from merged_inlines.admin import MergedInlineAdmin
class MyFirstInline(admin.TabularInline): pass class MySecondInline(admin.TabularInline): pass class MyModelAdmin(MergedInlineAdmin): inlines = [MyFirstInline,MySecondInline] admin.site.register(MyModel,MyModelAdmin)
Note that regardless of the Inline class used (TabularInline or StackedInline), Merged Inlines currently only renders as a tabular inline.
You can use merged_field_order in your MergedInlineAdmin class to set the order of the fields. The list/type must contain all of fields that will be editable in the admin: to exclude fields from the formset, use the builtin ModelAdmin exclude function.
class MyInline(admin.TabularInline): exclude = ('my_unwanted_field') class MyModelAdmin(MergedInlineAdmin): inlines = [MyInline] merged_field_order = ('put_this_field_first','followed_by_this_field','and_then_this_one')
This option determines what field will be used to sort your merged inline models. The shared models must both have the shared field, otherwise an Exception will be raised. If no field is specified, id will be used.
class BookInline(admin.TabularInline): model = Book class PoemInline(admin.TabularInline): model = Poem class AuthorAdmin(MergedInlineAdmin): merged_inline_order = 'year'