Group fieldsets or inlinegroups into tabs for django admin's changeform.
Project description
django-tabbed-changeform-admin
Group fieldsets or inlinegroups into tabs for django admin's changeform.
Install
pip install django-tabbed-changeform-admin
Usgae
pro/settings.py
Note:
- We used jquery and jquery-ui's static files, so we MUST add django_static_jquery3 and django_static_jquery_ui in INSTALLED_APPS.
- We override admin/change_form.html, so we MUST add django_tabbed_changeform_admin in INSTALLED_APPS.
INSTALLED_APPS = [
....
'django_static_jquery3',
'django_static_jquery_ui',
'django_tabbed_changeform_admin',
...
]
app/admin.py
Note:
- Create ModelAdmin based on DjangoTabbedChangeformAdmin.
- Add a sepcial class name to every fieldset or inline group.
- Add
tabs
property to admin. It's a list of (Tab-Name, Content-Class-Names) pair. - You can get
tabs
dynamically by overriding methodget_tabs(self, request, object_id, form_url, extra_context)
.
from django.contrib import admin
from django_tabbed_changeform_admin.admin import DjangoTabbedChangeformAdmin
from .models import Book
from .models import Character
class CharacterInline(admin.TabularInline):
model = Character
extra = 0
classes = ["tab-character-inline"]
class BookAdmin(DjangoTabbedChangeformAdmin, admin.ModelAdmin):
save_on_top = True
list_display = ["name", "published_time", "publisher"]
fieldsets = [
(None, {
"fields": ["name"],
"classes": ["tab-basic"],
}),
("Publish Information", {
"fields": ["published_time", "publisher"],
"classes": ["tab-publish-info"],
})
]
inlines = [
CharacterInline,
]
tabs = [
("Basic Information", ["tab-basic", "tab-publish-info"]),
("Characters", ["tab-character-inline"]),
]
admin.site.register(Book, BookAdmin)
Releases
v0.1.0 2020/03/17
- First releases.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-tabbed-changeform-admin-0.1.0.tar.gz
.
File metadata
- Download URL: django-tabbed-changeform-admin-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d26201f06d4195aa042cf8167413b449937872b262be7926372ce625759df86 |
|
MD5 | ac879754c8c9c5da224510dae32fd340 |
|
BLAKE2b-256 | e2cdf84b47966ebd85d766ce19683f4f385f11bb1f4bfd3db9b573a405fd29ae |