Skip to main content

Edc custom django ModelAdmin mixins, tags and templates for clinicedc/edc projects

Project description

pypi actions codecov downloads

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

edc-model-admin-0.3.47.tar.gz (57.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

edc_model_admin-0.3.47-py3-none-any.whl (77.1 kB view details)

Uploaded Python 3

File details

Details for the file edc-model-admin-0.3.47.tar.gz.

File metadata

  • Download URL: edc-model-admin-0.3.47.tar.gz
  • Upload date:
  • Size: 57.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for edc-model-admin-0.3.47.tar.gz
Algorithm Hash digest
SHA256 a5323882f0584040cea4a37af1a640563bcdd4b36f37f176f5aba7c8e7ba0a0d
MD5 472e7a436933d3e3da9ac5e8aa531c59
BLAKE2b-256 7a557c7e86077f7ca93b4ebb28f33103324277d8031a101a26f651a0c64c55b0

See more details on using hashes here.

File details

Details for the file edc_model_admin-0.3.47-py3-none-any.whl.

File metadata

File hashes

Hashes for edc_model_admin-0.3.47-py3-none-any.whl
Algorithm Hash digest
SHA256 aabf2027bd0b871da6dbae6d760f8e841edc43360de33fc82afc7bc0412bc5dd
MD5 329f0411f3c290e1a8ec8042f6c0e765
BLAKE2b-256 4881d071265911ddcf775ec442842e1f68d87f1acd910f6fc24dd205dbed29ff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page