Extensions to Django's admin site to add an ajax view.
Project description
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, subclassBaseCustomUrlAdminand implement the'get_custom_urls'function
BaseAjaxModelAdmin
- in your
ModelAdmin, subclassBaseAjaxModelAdminand 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
ModelAdminwill only display fields declared in afieldsetso 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 anyfieldsetsyou might have declared in yourModelAdmin. If you know of a good way to lift this restriction, please submit a patch.
BaseAjaxModelForm
- set the
ajax_change_fieldto be the name of the form field whose change triggers the ajax call OR set theajax_change_fieldsto a list of field names whose change triggers the ajax call - in your form, set the
dynamic_fieldsproperty 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.jsis available in your static content. - The ajax call gets the new form and replaces all the elements with the class of
.modulewith 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_admin_ext-3.0.2.tar.gz.
File metadata
- Download URL: django_admin_ext-3.0.2.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61bcc5df647fc9c7080f5045f1f9faf4f8302999eefbdc7030faed5c9c73b0aa
|
|
| MD5 |
51151a114b51d765c18794954f614263
|
|
| BLAKE2b-256 |
3e69df2152aff35623b67b867b73d21216210500f5324490d4c5b9a1ba0b0f52
|
File details
Details for the file django_admin_ext-3.0.2-py3-none-any.whl.
File metadata
- Download URL: django_admin_ext-3.0.2-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82ce862cb139e41d7327a94e1d9da0b2613bf215aaedf54dba9aa4269e2d3651
|
|
| MD5 |
664beaa4aed962f47eb8aa5a51a56c56
|
|
| BLAKE2b-256 |
9a2bc304e59c5a4d879aa416dac8a32a1f2d56c8a8f856de940de56e79f4407d
|