edc-model-admin
Edc custom django ModelAdmin mixins, tags and templates
ModelAdminFormAutoNumberMixin
Overrides ModelAdmin’s get_form to insert question numbers and the DB field names.
ModelAdminNextUrlRedirectMixin
Skips the changelist and redirects to the next CRF or Requisition listed in an edc visit schedule if “[Save and Next]” is clicked instead of “[SAVE]”
class BaseModelAdmin:
search_fields = ("subject_identifier",)
add_form_template = "edc_model_admin/admin/change_form.html"
change_form_template = "edc_model_admin/admin/change_form.html"
change_list_template = "edc_model_admin/admin/change_list.html"
@admin.register(CrfTwo)
class CrfTwoAdmin(BaseModelAdmin, ModelAdminNextUrlRedirectMixin, admin.ModelAdmin):
show_save_next = True
show_cancel = True
You need to use the included change_form.html to override the submit buttons on the admin form.
See also:: edc_visit_schedule
ModelAdminRedirectOnDeleteMixin
Redirects the admin form on save to a view other than the default changelist if post_url_on_delete_name is set.
@admin.register(CrfFive)
class CrfFiveAdmin(ModelAdminRedirectOnDeleteMixin, admin.ModelAdmin):
post_url_on_delete_name = "dashboard2_app:dashboard_url"
def post_url_on_delete_kwargs(self, request, obj):
return {'subject_identifier': obj.subject_identifier}
You can also store url names in the request object if used together with the Middleware from edc_dashboard and edc_subject_dashboard. This is useful if you do not know the namespace until deployment.
For example, add to settings:
MIDDLEWARE=[
...,
'edc_dashboard.middleware.DashboardMiddleware',
'edc_subject_dashboard.middleware.DashboardMiddleware',
],
DASHBOARD_URL_NAMES={
'subject_dashboard_url': 'dashboard_app:subject_dashboard_url',
},
and then declare the model admin class:
@admin.register(CrfFive)
class CrfFiveAdmin(ModelAdminRedirectOnDeleteMixin, admin.ModelAdmin):
post_url_on_delete_name = "subject_dashboard_url"
def post_url_on_delete_kwargs(self, request, obj):
return {'subject_identifier': obj.subject_identifier}
ModelAdminRedirectOnDeleteMixin will attempt to get the urlname from the request object using post_url_on_delete_name as a dictionary key.
Template themes
You can change the default theme colors.
EDC_MODEL_ADMIN_CSS_THEME = "edc_indigo"
Options are:
edc_indigo
edc_deep_purple
edc_purple
ModelForm Save Delay
You can configure the save buttons on the CRF and PRN model forms to disable for a few seconds after clicked by the user.
# settings.py
EDC_MODEL_ADMIN_SAVE_DELAY = 3000 # delay for 3 seconds
The default is 0 seconds.
Where internet connections are slow a user may think they did not click the save button and click it again. This may lead to multiple submissions of the same form and raise an IntegrityError. Save delay disables the button for 3 seonds (or as configured) to minimize the chance of this type of error occuring.
See also ModelAdminSubjectDashboardMixin and the change_form.html.
Metadata
Release files for edc-model-admin 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| edc_model_admin-1.0.3.tar.gz | 68.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| edc_model_admin-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 164.3 kB
Release files / edc_model_admin-1.0.3.tar.gz
| Download URL | edc_model_admin-1.0.3.tar.gz |
|---|---|
| Size | 68.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd31f81595c4a4b97999b5ad53dabd5914c6d2ba3ce7fe5e8da4dee57a8dd1cd
|
|
BLAKE2b-256 checksum How to use checksums |
81954c9d0dd61d8f8a54558a8a77707f99677116566bf92d2a5f9afae754a6a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|
Release files / edc_model_admin-1.0.3-py3-none-any.whl
| Download URL | edc_model_admin-1.0.3-py3-none-any.whl |
|---|---|
| Size | 95.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a3655914a094b817da6720bcbf796408d81bb02c68becd571ac347fa04e8920
|
|
BLAKE2b-256 checksum How to use checksums |
b1e43823e8286a5237177d29577fd1767e645894db5b4da7e1ad5c3f2043e6dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|