Skip to main content

Easily add tabs to django admin forms.

Project description

PyPI version build-status

Django tabbed admin

Simple library to easilly add tabs to admin forms. It also allows users to re-order inlines and fieldsets. Django tabbed admin is compatible with django-grappelli and django-gipsy.

https://box.everhelper.me/attachment/256054/rSqCFM20d245qFlG5z64EgiOVpeuTU3P/341506-h1u4JrpaUan0tG2e/screen.png

Grappelli:

https://box.everhelper.me/attachment/256057/rSqCFM20d245qFlG5z64EgiOVpeuTU3P/341506-kQnZXKsO0pfrU4cI/screen.png

Install

It is strongly recommanded to install this theme from GIT with PIP onto you project virtualenv.

From PyPi

pip install django-tabbed-admin

From Github

https://github.com/omji/django-tabbed-admin#egg=tabbed_admin

setup

Simply add the app in your installed apps list in settings.py

INSTALLED_APPS = (
    ...
    'tabbed_admin'
    ...
)

Django-tabbed-admin by default requires Jquery UI tabs plugin in order to work. It is packaged with the static files required to make it funcitonnal, however, they are not activated by default to avoid a conflict with other libraries.

In order to activate the Jquery UI statics, add the following line to the project settings:

TABBED_ADMIN_USE_JQUERY_UI = True

Configure admin tabs

In order to add tabs to a model admin, it should inherit from tabbed_admin.TabbedModelAdmin and contain a tabs attribute. The tab attribute configuration tries to remain similar to the fieldsets and inlines setup logic.

from django.contrib import admin

from tabbed_admin import TabbedModelAdmin
from .models import Band, Musician, Album


class MusicianInline(admin.StackedInline):
    model = Musician
    extra = 1


class AlbumInline(admin.TabularInline):
    model = Album
    extra = 1


@admin.register(Band)
class BandAdmin(TabbedModelAdmin):
    model = Band

    tab_overview = (
        (None, {
            'fields': ('name', 'bio', 'style')
        }),
        MusicianInline,
        ('Contact', {
            'fields': ('agent', 'phone', 'email')
        })
    )
    tab_album = (
        AlbumInline,
    )
    tabs = [
        ('Overview', tab_overview),
        ('Albums', tab_album)
    ]

Be warned that the tabs will completely reset the fieldsets and inlines attributes in order to avoid conflicts during the form saving. Both attributes are overwritten with the entries passed to the tabs attribute. For the same reasons, it is highly recommanded not to overwrite get_fieldsets or get_inlines.

You can pass and modify the tabs dynamically the same way you would do for fieldsets or inlines.

class BandAdmin(TabbedModelAdmin):
    model = Band

    tab_overview = (
        (None, {
            'fields': ('name', 'bio', 'style')
        }),
        MusicianInline,
        ('Contact', {
            'fields': ('agent', 'phone', 'email')
        }),
    )
    tab_ressources = (
        ConcertInline,
        AlbumInline,
    )
    tabs = [
        ('Overview', tab_overview),
        ('Ressources', tab_ressources)
    ]

    def get_tabs(self, request, obj=None):
        tabs = self.tabs
        if obj is not None:
            tab_overview = self.tab_overview + ('Social', {
                'fields': ('website', 'twitter', 'facebook')
            })
            tab_ressources = self.tab_ressources + (InterviewInline, )
            tabs = [
                ('Overview', tab_overview),
                ('Ressources', tab_ressources)
            ]
        self.tabs = tabs
        return super(BandAdmin, self).get_tabs(request, obj)

Contribution

Please feel free to contribute. Any help and advices are much appreciated. You will find an exemple application to run and develop the library easily.

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

django-tabbed-admin-0.0.2.tar.gz (20.5 kB view details)

Uploaded Source

File details

Details for the file django-tabbed-admin-0.0.2.tar.gz.

File metadata

File hashes

Hashes for django-tabbed-admin-0.0.2.tar.gz
Algorithm Hash digest
SHA256 32a65d6e00877f9e4e0bc54f6c03e3a1dbe6ebaf1878cb5d9ee230077ea20ec5
MD5 d3abac25334b989158ccfaa353148e8d
BLAKE2b-256 d62454a86fed30faef0ebedc0c7c052b81d9ef9fdd9a871e22264256072c8c89

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page