Skip to main content

Patched with 'ugettext/gettext' support for django-tabbed-admin

Project description

PyPI version build-status coverage

Django tabbed admin u

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. Patched with ‘ugettext/gettext’ selection to solve import error with later versions of Django, and to keep backwards compatibility for previous versions.

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-u

From Github

https://github.com/intp1/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.

Basically, a tuple can be created for each tab exactely the same way as for fieldsets, except that inlines can be added anywhere in between.

tab_overview = (
    (None, {
        'fields': ('name', 'bio', 'style')
    }),
    MusicianInline,
    ('Contact', {
        'fields': ('agent', 'phone', 'email')
    })
)

Then each tuple have to be passed to a tabs attribute prefixed by the verbose name to display within the tab:

tabs = [
    ('Overview', tab_overview),
    ('Albums', tab_album)
]

A full example would give:

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)
    ]

Configure tabs dynamically

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.

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)

Change the jquery ui

You can change the jquery ui css and js by either overriding the media in the admin class

class Media:
    css = {
        'all': ('css/jquery-ui.theme.min.css',)
    }

or by changing the the following settings,

TABBED_ADMIN_JQUERY_UI_CSS and TABBED_ADMIN_JQUERY_UI_JS

TABBED_ADMIN_JQUERY_UI_CSS = 'static/css/my-custom-jquery-ui.css'
TABBED_ADMIN_JQUERY_UI_JS = 'static/js/my-custom-jquery-ui.js'

Contribution

Please feel free to contribute. Any help and advices are much appreciated. You will find an example 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_u-1.0.4.tar.gz (65.0 kB view details)

Uploaded Source

Built Distribution

django_tabbed_admin_u-1.0.4-py2.py3-none-any.whl (95.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django_tabbed_admin_u-1.0.4.tar.gz.

File metadata

  • Download URL: django_tabbed_admin_u-1.0.4.tar.gz
  • Upload date:
  • Size: 65.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.8

File hashes

Hashes for django_tabbed_admin_u-1.0.4.tar.gz
Algorithm Hash digest
SHA256 90b98676037583b5cc91d2e864b31e712a16d9b5b471dd6ea7bdc178fc627eff
MD5 ff591878eaec7daf82b5311e72fbbe5f
BLAKE2b-256 48cef1676d310877e2a71b5d9c3c894758ddbc4f3bb2b6258e1304077dda511d

See more details on using hashes here.

File details

Details for the file django_tabbed_admin_u-1.0.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_tabbed_admin_u-1.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1dad0d53911fbbc0b2c435aa5d001274cbfd8dfe5e008410b99ff1f5c790aafa
MD5 a22973b25a555170118c664ea136d797
BLAKE2b-256 830d2bce3db9b23e3f9d862b05321dfa98162924ce172cbd410883735e432f5e

See more details on using hashes here.

Supported by

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