All Projects → inueni → Django Subadmin

inueni / Django Subadmin

Licence: mit
A special kind of ModelAdmin that allows it to be nested within another ModelAdmin

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Django Subadmin

Django Blogging System
This is blog system created using Django 1.11.4 and Python3
Stars: ✭ 11 (-90.83%)
Mutual labels:  django, django-admin
E Commerce 2 django
Guest register, user register, user login, user logout, account home page, product view history, change password, reset password, change name, send activation email when register, resend activation email, add shipping address, add billing address, add nickname to the addresses, edit shipping address, edit billing address, view list of your addresses, reuse shipping addresses when order products, reuse billing addresses when ordeer products, show sales analytics if staff or admin only using -chart.js-, get analytics data with Ajax, receive marketing email, change if user will receive marketing email or not by admin, send contact message with Ajax, products list, product detail, download product detail as a PDF file, download digital product files -if the user purchased that digital product only-, orders list, list of digital products files, order detail, download order detail as a PDF file, verify order ownership with Ajax -to secure order detail page-, show cart products, add or remove product from cart, checkout page, thanks page when order placed successfully, add or reuse payment method, add or reuse payment method with Ajax, search products by title, search products by description, search products by price, search products by tag title, write tags for products -by admin only-, auto fill contact email, full name if user logged in.
Stars: ✭ 20 (-83.33%)
Mutual labels:  django, django-admin
Django Oml
Object Moderation Layer
Stars: ✭ 12 (-90%)
Mutual labels:  django, django-admin
Awesome Django
The Best Django Resource, Awesome Django for mature packages.
Stars: ✭ 591 (+392.5%)
Mutual labels:  django, django-admin
Django Admin Material
A Django Admin interface based on Material Design by Google
Stars: ✭ 74 (-38.33%)
Mutual labels:  django, django-admin
Django Admin Bootstrap
Responsive Theme for Django Admin With Sidebar Menu
Stars: ✭ 787 (+555.83%)
Mutual labels:  django, django-admin
Django Suit Daterange Filter
Filter for django-admin allowing lookups by date range
Stars: ✭ 13 (-89.17%)
Mutual labels:  django, django-admin
Django Flat Theme
A flat theme for Django admin interface. Modern, fresh, simple.
Stars: ✭ 415 (+245.83%)
Mutual labels:  django, django-admin
Awesome Django Cn
Django 优秀资源大全。
Stars: ✭ 1,153 (+860.83%)
Mutual labels:  django, django-admin
Django Polymorphic
Improved Django model inheritance with automatic downcasting
Stars: ✭ 1,135 (+845.83%)
Mutual labels:  django, django-admin
Django Pagedown
A django app that allows the easy addition of Stack Overflow's "PageDown" markdown editor to a django form field, whether in a custom app or the Django Admin
Stars: ✭ 500 (+316.67%)
Mutual labels:  django, django-admin
Django Admin Relation Links
An easy way to add links to relations in the Django Admin site.
Stars: ✭ 87 (-27.5%)
Mutual labels:  django, django-admin
Django Ordered Model
Get your Django models in order
Stars: ✭ 476 (+296.67%)
Mutual labels:  django, django-admin
Django Phantom Theme
Phantom is theme for django admin with many widgets, based on Twitter bootstrap 3.x.
Stars: ✭ 18 (-85%)
Mutual labels:  django, django-admin
Django Nested Admin
Django admin classes that allow for nested inlines
Stars: ✭ 463 (+285.83%)
Mutual labels:  django, django-admin
Requery
Store e run queries on database to help system manager of a Django website
Stars: ✭ 12 (-90%)
Mutual labels:  django, django-admin
Django Cruds Adminlte
django-cruds is simple drop-in django app that creates CRUD for faster prototyping
Stars: ✭ 373 (+210.83%)
Mutual labels:  django, django-admin
Django Object Actions
A Django app for easily adding object tools in the Django admin
Stars: ✭ 374 (+211.67%)
Mutual labels:  django, django-admin
Django Admin Numeric Filter
Numeric filters for Django admin
Stars: ✭ 46 (-61.67%)
Mutual labels:  django, django-admin
Awesome Django
Repository mirror of GitLab: https://gitlab.com/rosarior/awesome-django This repository is not monitored for issues, use original at GitLab.
Stars: ✭ 8,527 (+7005.83%)
Mutual labels:  django, django-admin

django-subadmin

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.

Suported Python and Django releases

Current release of django-subadmin is 2.0.1 and it supports Python 3 only and Django versions 2.0 and up (including Django 3.0).

There is also a legacy 1.9.3 release with support for Python 2.7 and Django versions 1.9, 1.10 and 1.11. This release is no longer maintained and supported, but it's made available for legacy applications.

Verison numbering

django-subadmin versions follow Django version numbers. django-subadmin major and minor version numbers equal the minimal compatible django release.

Installation

The easiest and recommended way to install django-subadmin is from PyPI

pip install django-subadmin

You 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.

# settings.py

INSTALLED_APPS = (
    ...
    'subadmin',
    ...
)

Example Usage

Sometimes things are best explained by an example. Let's say you have two related models.

# models.py

class MailingList(models.Model):
    name = models.CharField(max_length=100)


class Subscriber(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 use InlineModelAdmin, which is not very practical when dealing with large number of related objects, plus, you loose all the cool functionality of ModelAdmin like searching, filtering, pagination, etc ...

This is where SubAdmin comes in.

# admin.py

from subadmin import SubAdmin, RootSubAdmin
from .models import MailingList, Subscriber

# Instead of admin.ModelAdmin we subclass SubAdmin,
# we also set model attribute

class SubscriberSubAdmin(SubAdmin): 
    model = Subscriber
    list_display = ('username',)


# Since this is the top level model admin, which will be registred with admin.site,
# we subclass RootSubAdmin and set subadmins attribute

class MailingListAdmin(RootSubAdmin):
    list_display = ('name',)

    subadmins = [SubscriberSubAdmin]
    

admin.site.register(MailingList, MailingListAdmin)

With 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.

Caveats

In 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.

Also, 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 stock ModelForm implementation and adjust your code as neccesarry.

Screenshots

alt text

SubAdmin instances are accesible 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.


alt text

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.


alt text

When 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.

If you want to see it in action, or get a more in-depth look at how to set everything up, check out https://github.com/inueni/django-subadmin-example.

Stability

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].