Skip to main content

Extensions to Django's admin site.

Currently Includes:

  • BaseCustomUrlAdmin: hook to provide additional urls to your model admin.
  • BaseAjaxModelAdmin: hook to have a form that gets some of it's form fields dynamically depending on a certain field choice.
  • BaseAjaxModelForm: form to help setup and save dynamic fields based on other fields chosen.

USAGE

Take a look at the example project for a more detailed example.

BaseCustomUrlAdmin

  • in your ModelAdmin, subclass BaseCustomUrlAdmin and implement the 'get_custom_urls' function

BaseAjaxModelAdmin

  • in your ModelAdmin, subclass BaseAjaxModelAdmin and make sure your form is pointing to your dynamic form.
  • there will be a new url that ends with /ajax/ that handles the ajax request.
  • Django's ModelAdmin will only display fields declared in a fieldset so we make sure the Ajax fields don't display when they don't have enough data to be present, and that they do display when they do. Because of this, we currently are not respecting any fieldsets you might have declared in your ModelAdmin. If you know of a good way to lift this restriction, please submit a patch.

BaseAjaxModelForm

  • set the ajax_change_field to be the name of the form field whose change triggers the ajax call OR set the ajax_change_fields to a list of field names whose change triggers the ajax call
  • in your form, set the dynamic_fields property to return a dictionary whose keys are the field names and values are the instantiated fields.
    @property
    def dynamic_fields(self):
        return {
            'my_field': CharField(initial="hello world!", label="Greeting"),
        }
    
  • when the change field is present either in a forms initial data or submitted data, the form will add all your dynamic fields to it, and when saving, the form will make sure all your dynamic field values are saved to the instance.
  • make sure the file in djadmin_ext/static/djadmin_ext/admin_ajax.js is available in your static content.
  • The ajax call gets the new form and replaces all the elements with the class of .module with the updated form.
  • NOTE: this will blow out any inline forms you have declared, so if you need inline forms, we'd be happy to accept a patch making it possible.

Testing

To test the admin, we wrote playwright tests. The tests will try to start django's test server, open a browser, execute the tests and verify the actions on the page behave as expected.

python setup.py test

Release files for django-admin-ext 3.0.3

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-admin-ext 3.0.3
File Size Uploaded
django_admin_ext-3.0.3.tar.gz 12.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-admin-ext 3.0.3
File Interpreter ABI Platform
django_admin_ext-3.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 25.7 kB

Release files / django_admin_ext-3.0.3.tar.gz

Download URL django_admin_ext-3.0.3.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7b00c9a7e0f296da8c356852ac0e0db1967889940b8864560103dae57046b833
BLAKE2b-256 checksum
How to use checksums
f67b59096f2a9f0dcd410765f689c11faeadedf18b48589b50bff96294de8206
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / django_admin_ext-3.0.3-py3-none-any.whl

Download URL django_admin_ext-3.0.3-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e6ca0f607e8bbc419661e9f4b3d22fd39a95a0b5bdadae5fd0e756b29f8b6e6
BLAKE2b-256 checksum
How to use checksums
e29c581d7535edd27cc73e3946c040f796214c99f55e30b914490f16004261c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release history Release notifications | RSS feed

This release

3.0.3 This release

2 release files

3.0.2

2 release files

3.0.1

2 release files

1.0.2

1 release file

1.0.1

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.1

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