Edc custom django ModelAdmin mixins, tags and templates for clinicedc/edc projects
Project description
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.
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
File details
Details for the file edc-model-admin-0.3.21.tar.gz
.
File metadata
- Download URL: edc-model-admin-0.3.21.tar.gz
- Upload date:
- Size: 46.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d714421dbc9709bcbee0fe249151214dd4f8c57e6caf46c04257aee3fd5616a0 |
|
MD5 | 87e8ea3ad4837b882899702bf984279a |
|
BLAKE2b-256 | 99167211e18415259c6d958b21cd3c50b58c349fe00e0b379d480b5527291424 |
File details
Details for the file edc_model_admin-0.3.21-py3-none-any.whl
.
File metadata
- Download URL: edc_model_admin-0.3.21-py3-none-any.whl
- Upload date:
- Size: 58.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 836eab9371132c30c3d9e92661173b5794eddfaaf95031dd6a150f908f21ac89 |
|
MD5 | 3ebaca45e3624d04f163db3ce42b5455 |
|
BLAKE2b-256 | 8a89c172acb231ec06fbacde15392bdc312c606ec51a3fc536a7d5f3cf7d5676 |