Skip to main content

Your project description goes here

Project description

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.

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-custom-modal-admin-0.2.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

django_custom_modal_admin-0.2.0-py2.py3-none-any.whl (4.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-custom-modal-admin-0.2.0.tar.gz.

File metadata

  • Download URL: django-custom-modal-admin-0.2.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for django-custom-modal-admin-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e50810e82f4f4f60c7dfbb7260602f8c6e9172a741aa4ac4dbe639ef6d6ed9e4
MD5 8d8f97c6c7a8cbaf6f31722ca4ac5694
BLAKE2b-256 1e20f30b0cfd2e7398145693d05b82d864d76fad4d1c2325068036c4050f2cf1

See more details on using hashes here.

File details

Details for the file django_custom_modal_admin-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: django_custom_modal_admin-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for django_custom_modal_admin-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3e078f99697c89f14ae3223aa982f975df440ba4382fcc92e5c3ceec02887851
MD5 66f6099920ab616c0d94c43af11c5756
BLAKE2b-256 70eaa519c444375d20e0e45d04b35fb02ecf622954e755b788c73ac2ccb0b4d4

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