Skip to main content

Add toolbar in every item line in django's changelist view, and on top of django's changeform view.

Project description

django-object-tools-admin

Add toolbar in every item line in django's changelist view, and on top of django's changeform view.

Install

pip install django-object-toolbar-admin

Usage

pro/settings.py

INSTALLED_APPS = [
    ...
    'django_static_fontawesome',
    'django_object_toolbar_admin',
    ...
]
  • Add django_static_fontawesome and django_object_toolbar_admin applications in INSTALLED_APPS.

app/admin.py

from django.contrib import admin
from django_object_toolbar_admin.admin import DjangoObjectToolbarAdmin
from .models import Category

class CategoryAdmin(DjangoObjectToolbarAdmin, admin.ModelAdmin):
    list_display = ["name", "django_object_toolbar", "my_toolbar"]

    django_object_toolbar_changeform_buttons = [
        "print",
        "export",
        "bye",
    ]
    # define default toolbar
    django_object_toolbar_buttons = [
        "print",
        "export",
        'bye',
    ]

    def print(self, obj):
        return "/print"
    print.icon = "fas fa-print"
    print.title = "Print"
    print.help_text = "Print the object information..."
    
    def export(self, obj):
        return "/export"
    export.icon = "fas fa-save"
    export.title = "Export"

    # define my toolbar
    def my_toolbar(self, obj):
        return self.get_django_object_toolbar("my_toolbar_buttons", obj)
    my_toolbar.short_description = "My Toolbar"

    my_toolbar_buttons = [
        "delete",
        "say_hi",
    ]

    def delete(self, obj):
        return "/delete"
    delete.icon = "fas fa-trash"
    delete.title = "Delete"

    def say_hi(self, obj):
        return "javascript:alert('hi {}');".format(obj.pk)
    say_hi.icon = "fas fa-music"
    say_hi.title = "Say Hi!"

admin.site.register(Category, CategoryAdmin)
  • Buttons in django_object_toolbar_changeform_buttons will display on top of changeform view.
  • Buttons in django_object_toolbar_buttons or my_toolbar_buttons will display in every line in changelist view. You need to put django_object_toolbar or my_toolbar in list_display.
  • A button can be a method of admin or a method of model instance.
  • A button method returns the link of the button.
  • A button method tasks extra configs:
    • button.title
    • button.icon
    • button.help_text
    • button.target
    • button.klass

Releases

v0.1.1 2020/09/23

  • Fix Button.from_dict calling problem.
  • Add i18n.
  • Add app_requires.

v0.1.0 2020/05/24

  • First release.

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-object-toolbar-admin-0.1.1.tar.gz (5.6 kB view details)

Uploaded Source

File details

Details for the file django-object-toolbar-admin-0.1.1.tar.gz.

File metadata

  • Download URL: django-object-toolbar-admin-0.1.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.8

File hashes

Hashes for django-object-toolbar-admin-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e71fd34370019dfcd86e4d92aa35063b29f522c8bad775c78fbdbdbbe173e2a8
MD5 fda2066458d370cfe65cee5d03cd1833
BLAKE2b-256 c39eff385ff5369f64b7a2da2a4f112d2c37b2a6871d03fba26f251ea7777041

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