{"id":13419536,"url":"https://github.com/inueni/django-subadmin","last_synced_at":"2025-12-14T01:27:25.061Z","repository":{"id":43612572,"uuid":"110479438","full_name":"inueni/django-subadmin","owner":"inueni","description":"A special kind of ModelAdmin that allows it to be nested within another ModelAdmin ","archived":false,"fork":false,"pushed_at":"2024-09-03T22:26:13.000Z","size":41,"stargazers_count":141,"open_issues_count":2,"forks_count":18,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-09-23T13:48:27.411Z","etag":null,"topics":["django","django-admin","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/inueni.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-12T23:52:27.000Z","updated_at":"2024-08-16T14:20:28.000Z","dependencies_parsed_at":"2024-06-06T13:03:57.376Z","dependency_job_id":"0c1a0b93-0ebb-467c-b94c-6bfb60d0f82c","html_url":"https://github.com/inueni/django-subadmin","commit_stats":{"total_commits":22,"total_committers":5,"mean_commits":4.4,"dds":0.2727272727272727,"last_synced_commit":"ac6ce5de8a6d426eecbb7938b9345817c7f87443"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inueni%2Fdjango-subadmin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inueni%2Fdjango-subadmin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inueni%2Fdjango-subadmin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inueni%2Fdjango-subadmin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inueni","download_url":"https://codeload.github.com/inueni/django-subadmin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221541907,"owners_count":16840118,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-admin","python"],"created_at":"2024-07-30T22:01:17.357Z","updated_at":"2025-12-14T01:27:20.015Z","avatar_url":"https://github.com/inueni.png","language":"Python","readme":"# django-subadmin\n\n`django-subadmin` provides a special kind of `ModelAdmin`, called `SubAdmin`, that allows it to be nested within another `ModelAdmin` instance. Similar to django's built-in `InlineModelAdmin`, it allows editing of related objects, but instead of doing it inline, it gives you a full `ModelAdmin` as sub-admin of parent `ModelAdmin`. Like `InlineModelAdmin` it works on models related by `ForeignKey`. Multiple `SubAdmin` instances can be nested within a single `ModelAdmin` or `SubAdmin` allowing for multi-level nesting.\n\n### Supported Python and Django releases\n\nCurrent release of `django-subadmin` supports Django versions 3.2 and up (including Django 4).\n\n#### Verison numbering\n\ndjango-subadmin versions follow Django version numbers. django-subadmin major and minor version numbers equal the minimal compatible django release.\n\n## Installation\n\nThe easiest and recommended way to install `django-subadmin` is from [PyPI](https://pypi.python.org/pypi/django-subadmin)\n\n```\npip install django-subadmin\n```\n\nYou need to add `subadmin` to `INSTALLED_APPS` in your projects `settings.py`, otherwise `django` will not be able to find the necessary templates and template tags.\n\n```\n# settings.py\n\nINSTALLED_APPS = (\n    ...\n    'subadmin',\n    ...\n)\n```\n\n## Example Usage\n\nSometimes things are best explained by an example. Let's say you have two related models.\n\n```python\n# models.py\n\nclass MailingList(models.Model):\n    name = models.CharField(max_length=100)\n\n\nclass Subscriber(models.Model):\n    mailing_list = models.ForeignKey(MailingList)\n    username = models.CharField(max_length=100)\n```\n\nIf you wish to display only subscribers belonging to a particular mailing list in django admin, your only option is to use `InlineModelAdmin`, which is not very practical when dealing with a large number of related objects, plus, you loose all the cool functionality of `ModelAdmin` like searching, filtering, pagination, etc ...\n\nThis is where `SubAdmin` comes in.\n\n```python\n# admin.py\n\nfrom subadmin import SubAdmin, RootSubAdmin\nfrom .models import MailingList, Subscriber\n\n# Instead of admin.ModelAdmin we subclass SubAdmin,\n# we also set model attribute\n\nclass SubscriberSubAdmin(SubAdmin): \n    model = Subscriber\n    list_display = ('username',)\n\n\n# Since this is the top level model admin, which will be registred with admin.site,\n# we subclass RootSubAdmin and set subadmins attribute\n\nclass MailingListAdmin(RootSubAdmin):\n    list_display = ('name',)\n\n    subadmins = [SubscriberSubAdmin]\n    \n\nadmin.site.register(MailingList, MailingListAdmin)\n```\n\nWith just a few lines of code you get a fully functional `ModelAdmin`, that will automatically pull in just the relevant related objects, based on `ForeignKey` relation between the two models, it will also auto set `ForeignKey` fields for nested relations and exclude them from change form when adding and editing objects on subadmin.\n\n\n### Caveats\n\nIn order to properly support unique field validation (see Issue #7), `SubAdmin` will inject a small mixin into the form. This is done in the `get_form` method and if you override this method in your own classes, make sure to call `super()` or `perp_subadmin_form()` directly. See `subadmin` source code for more details.\n\nAlso, the injected mixin `SubAdminFormMixin` overrides `validate_unique` on the form. If your custom form overrides this method as well, have a look at `subadmin` source code for ways in which it differs from the stock `ModelForm` implementation and adjust your code as necessary.\n\n\n### Screenshots\n\n![alt text](https://github.com/inueni/django-subadmin-example/raw/master/screenshots/subadmin_screenshot_1.png?raw=true)\n\n `SubAdmin` instances are accessible from edit view of the `ModelAdmin` instance they are nested in. In the screenshot above you can see links to _Subscribers_ and _Messages_ subadmins (marked with red rectangle) for `MailingList` instance _Mailing list 5_.\n\n---\n\n![alt text](https://github.com/inueni/django-subadmin-example/raw/master/screenshots/subadmin_screenshot_2.png?raw=true)\n\n `SubAdmin` looks and behaves just like a regular `ModelAdmin`, but looking at breadcrumbs (marked with red rectangle), you can see it is nested within another `ModelAdmin`. Displayed `Subscribers` are limited to those related to `MailingList` instance _Mailing list 5_.\n\n---\n\n ![alt text](https://github.com/inueni/django-subadmin-example/raw/master/screenshots/subadmin_screenshot_3.png?raw=true)\n\nWhen adding or editing objects with `SubAdmin`, `ForeignKey` fields to parent instances are removed from the form and automatically set when saving. In this example `mailing_list` field is removed and value is set to parent `MailingList` instance _Mailing list 5_.\n\n\u003e If you want to see it in action, or get a more in-depth look at how to set everything up, check out \u003chttps://github.com/inueni/django-subadmin-example\u003e.\n\n## Stability\n\n`django-subadmin` has evolved from code that has been running on production servers since early 2014 without any issues. The code is provided **as-is** and the developers bear no responsibility for any issues stemming from it's use.\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finueni%2Fdjango-subadmin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finueni%2Fdjango-subadmin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finueni%2Fdjango-subadmin/lists"}