Skip to main content

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.

Release files for django-dynamic-resource-admin 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-dynamic-resource-admin 0.1.1
File Size Uploaded
django-dynamic-resource-admin-0.1.1.tar.gz 3.9 kB Details

Release files / django-dynamic-resource-admin-0.1.1.tar.gz

Download URL django-dynamic-resource-admin-0.1.1.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d3ce6eed41bc1c1faa14cb1d4dd204c903f8a196b9f1f8beb578d56d62d69c1e
BLAKE2b-256 checksum
How to use checksums
620e6c38d210bdd4de5860aad3d01a0d5c8c6fbb3cffee3642151892d41cba35
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page