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.1 2020/09/25

  • Fix js code wrapper from <style></style> to <script type="text/javascript"></script>.
  • Add license file.

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.1.tar.gz (3.9 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: django-dynamic-resource-admin-0.1.1.tar.gz
  • Upload date:
  • Size: 3.9 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-dynamic-resource-admin-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d3ce6eed41bc1c1faa14cb1d4dd204c903f8a196b9f1f8beb578d56d62d69c1e
MD5 d4ec12c26bdb78bb0a1767f6f70f2220
BLAKE2b-256 620e6c38d210bdd4de5860aad3d01a0d5c8c6fbb3cffee3642151892d41cba35

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