Skip to main content

Django custom modal admin

https://badge.fury.io/py/django-custom-modal-admin.svg/?style=flat-square https://readthedocs.org/projects/pip/badge/?version=latest&style=flat-square Coverage Status

Your project description goes here

Documentation

The full documentation is at https://django-custom-modal-admin.readthedocs.io.

Quickstart

Install Django custom modal admin:

pip install django-custom-modal-admin

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'custom_modal_admin',
    ...
)

Override CustomModalAdmin in your model admin:

@admin.register(ExampleModel)
class ExampleModelAdmin(CustomModalAdmin, admin.ModelAdmin):
    list_display = ("title", "subtitle", "description",)

    fieldsets = (
        (None, {"fields": (
            ("title", "subtitle", "description")
        )}),
    )

This admin add to your class Media this dependencies:

class Media:
    js = [
        'https://code.jquery.com/jquery-2.2.4.min.js',
        'https://code.jquery.com/ui/1.12.1/jquery-ui.min.js',
        'js/custom_modal_admin.js',
    ]
    css = {
        'all': (
            'https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css',
        ),
    }

take care of this media when override Media class.

To display the modal insert in your templates a target html tag, using django admin or adding it in template or wherever you want, for example:

<input
    class='js-django-admin-custom-modal' // this class is required
    data-target-name='load-template-modal' // this target name is required
    type='button'
    value='Click to show modal'
>

and the template of your modal with custom content:

<div data-django-admin-custom-modal="load-template-modal" style="display:none;">
    <span>This is a modal</span>
</div>

Now you can insert whatever you want in that modal.

You can also insert in the same block or display_field the admin and the button, for example:

<input
    class='js-django-admin-custom-modal'
    type='button'
    data-target-name='load-template-modal'
    value='Click to show modal'
>
<div data-django-admin-custom-modal="load-template-modal" style="display:none;">
    <span>This is a modal</span>
</div>

If you need to insert a modal for all your site, you can override base_site.html and insert in the extrastyle block the required css.

{% block extrastyle %}
{{ block.super }}
    <link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
{% endblock %}

And the required js into extrahead block:

{% block extrahead %}
    <script src="https://code.jquery.com/jquery-2.2.4.min.js" defer></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" defer></script>
    <script src="{% static 'js/custom_modal_admin.js' %}" defer></script>
{% endblock %}

With this last implementation you can avoid to inerith CustomModalAdmin in all yours admin.

Credits

Tools used in rendering this package:

History

0.2.0 (2021-11-22)

  • First release on PyPI.

Metadata

Release files for django-custom-modal-admin 1.0.0

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-custom-modal-admin 1.0.0
File Size Uploaded Provenance Actions
django_custom_modal_admin-1.0.0.tar.gz 85.0 kB Without provenance Details for django_custom_modal_admin-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-custom-modal-admin 1.0.0
File Interpreter ABI Platform Actions
django_custom_modal_admin-1.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for django_custom_modal_admin-1.0.0-py2.py3-none-any.whl

Total release size: 166.8 kB

Release files / django_custom_modal_admin-1.0.0.tar.gz

Download URL django_custom_modal_admin-1.0.0.tar.gz
Size 85.0 kB
Tags Source
SHA-256 checksum
How to use checksums
109797ec6de89fb4aea8fd04a36b54a8a460242792608811264a18873b84bed7
BLAKE2b-256 checksum
How to use checksums
39de3af37f3d010451e05bf86ab9fe96b3cfeab6ab79c6e2f215bdfcaee3054e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Release files / django_custom_modal_admin-1.0.0-py2.py3-none-any.whl

Download URL django_custom_modal_admin-1.0.0-py2.py3-none-any.whl
Size 81.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
3ffa1fc09d261110bb2c2632cadad0affcf0a2b286f30bdebcc4bf8bc7a8896a
BLAKE2b-256 checksum
How to use checksums
50968041c362ef115692cd98d59cf6a2fb4ecbe1d972c5430828bb388fef00fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Security for django-custom-modal-admin 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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