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


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-dynamic-resource-admin, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size django-dynamic-resource-admin-0.1.0.tar.gz (4.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page