Skip to main content

Add dynamic css & js resources to django's admin site.

Project description

django-dynamic-resource-admin

Add dynamic css & js resources to django's admin site.

Install

pip install django-dynamic-resource-admin

Usage

Note:

  1. We use template override mechanism, so you MUST add app name django_dynamic_resource_admin into INSTALLED_APPS.

  2. The parameter request pass to get_css&get_js is the request of this view.

  3. The parameters **kwargs pass to get_css&get_js are the paramters of admin view prameters.

  4. Every extra js part is wrappered with closure function, so that they will be NO local variables conflict. If you want to add a global variable, name it like: window.xxx = 123;.

    (function(){
        ...your js code...
    })();
    

pro/settings.py

INSTALLED_APPS = [
    ...
    'django_dynamic_resource_admin',
    ...
]

app/admin.py

from django.contrib import admin
from django_dynamic_resource_admin.admin import DjangoDynamicResourceAdmin
from .models import Book


class BookAdmin(DjangoDynamicResourceAdmin, admin.ModelAdmin):
    def get_css(self, request, **kwargs):
        csses = super().get_css(request)
        csses += [
"""
body{
    background-color: red;
}
""",
        ]
        return csses

admin.site.register(Book, BookAdmin)

How to add your custom css&js?

  • Override get_css to add extra css.
  • Override get_js to add extra js.
def get_css(self, request, **kwargs):
    extra_css = super().get_css(request, **kwargs)
    extra_css += [
        """body{xxx}""",
        """.title{xxx}"""
    ]
    return extra_css

def get_js(self, request, **kwargs):
    extra_js = super().get_js(request, **kwargs):
    extra_js += [
        """window.msg="hello world";""",
        """...""",
    ]
    return extra_js

Release

v0.1.0 2020/03/13

  • First realse.

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-dynamic-resource-admin-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file django-dynamic-resource-admin-0.1.0.tar.gz.

File metadata

  • Download URL: django-dynamic-resource-admin-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 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

Hashes for django-dynamic-resource-admin-0.1.0.tar.gz
Algorithm Hash digest
SHA256 af4a2d029a602adb33ff2148a07e1880c9b61c70dd654e5ddd2a762cda2db283
MD5 449c5b8dea12b835f3d85167d5efc493
BLAKE2b-256 652ec551b57e96ad7bbc65e2d07139428d90ba4fa6717a0a7051eae9e3ae1228

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