Package: django-subadmin
django-subadmindjango-subadminprovides a special kind ofModelAdmin, calledSubAdmin, that allows it to be nested within anotherModelAdmininstance. Similar to django's built-inInlineModelAdmin, it allows editing of related objects, but instead of doing it inline, it gives you a fullModelAdminas sub-admin of parentModelAdmin. LikeInlineModelAdminit works on models related byForeignKey. MultipleSubAdmininstances can be nested within a singleModelAdminorSubAdminallowing for multi-level nesting.Suported Python and Django releasesCurrent release ofdjango-subadminsupports Django versions 3.2 and up (including Django 4).Verison numberingdjango-subadmin versions follow Django version numbers. django-subadmin major and minor version numbers equal the minimal compatible django release.InstallationThe easiest and recommended way to installdjango-subadminis fromPyPIpip install django-subadminYou need to addsubadmintoINSTALLED_APPSin your projectssettings.py, otherwisedjangowill not be able to find the necessary templates and template tags.# settings.py

INSTALLED_APPS = (
    ...
    'subadmin',
    ...
)Example UsageSometimes things are best explained by an example. Let's say you have two related models.# models.pyclassMailingList(models.Model):name=models.CharField(max_length=100)classSubscriber(models.Model):mailing_list=models.ForeignKey(MailingList)username=models.CharField(max_length=100)If you wish to display only subscribers belonging to a particular mailing list in django admin, your only options is to useInlineModelAdmin, which is not very practical when dealing with large number of related objects, plus, you loose all the cool functionality ofModelAdminlike searching, filtering, pagination, etc ...This is whereSubAdmincomes in.# admin.pyfromsubadminimportSubAdmin,RootSubAdminfrom.modelsimportMailingList,Subscriber# Instead of admin.ModelAdmin we subclass SubAdmin,# we also set model attributeclassSubscriberSubAdmin(SubAdmin):model=Subscriberlist_display=('username',)# Since this is the top level model admin, which will be registred with admin.site,# we subclass RootSubAdmin and set subadmins attributeclassMailingListAdmin(RootSubAdmin):list_display=('name',)subadmins=[SubscriberSubAdmin]admin.site.register(MailingList,MailingListAdmin)With just a few lines of code you get a fully functionalModelAdmin, that will automatically pull in just the relevant related objects, based onForeignKeyrelation between the two models, it will also auto setForeignKeyfields for nested relations and exclude them from change form when adding and editing objects on subadmin.CaveatsIn order to properly support unique field validation (see Issue #7),SubAdminwill inject a small mixin into the form. This is done in theget_formmethod and if you override this method in your own classes, make sure to callsuper()orperp_subadmin_form()directly. Seesubadminsource code for more details.Also, the injected mixinSubAdminFormMixinoverridesvalidate_uniqueon the form. If your custom form overrides this method as well, have a look atsubadminsource code for ways in which it differs from stockModelFormimplementation and adjust your code as neccesarry.ScreenshotsSubAdmininstances are accesible from edit view of theModelAdmininstance they are nested in. In the screenshot above you can see links toSubscribersandMessagessubadmins (marked with red rectangle) forMailingListinstanceMailing list 5.SubAdminlooks and behaves just like a regularModelAdmin, but looking at breadcrumbs (marked with red rectangle), you can see it is nested within anotherModelAdmin. DisplayedSubscribersare limited to those related toMailingListinstanceMailing list 5.When adding or editing objects withSubAdmin,ForeignKeyfields to parent instances are removed from the form and automatically set when saving. In this examplemailing_listfield is removed and value is set to parentMailingListinstanceMailing list 5.If you want to see it in action, or get a more in-depth look at how to set everything up, check outhttps://github.com/inueni/django-subadmin-example.Stabilitydjango-subadminhas evolved from code that has been running on production servers since early 2014 without any issues. The code is providedas-isand the developers bear no responsibility for any issues stemming from it's use.