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.54.tar.gz (63.6 kB view details)

Uploaded Source

Built Distribution

edc_model_admin-0.3.54-py3-none-any.whl (85.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: edc-model-admin-0.3.54.tar.gz
  • Upload date:
  • Size: 63.6 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.54.tar.gz
Algorithm Hash digest
SHA256 8eec82f0e5aae5e901a52496985e3f6d95d86df2e3d25ff3754f80293fc88288
MD5 c4252d89f01789ed56b9a583471de0a4
BLAKE2b-256 e348b9dfe907272da6f2ffb63c50adccbd01358ac2d2c89c643d4d53a5e29e39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for edc_model_admin-0.3.54-py3-none-any.whl
Algorithm Hash digest
SHA256 104cdaf777de73a97e94768bf803216d0586d5770b89194be68fa0d09bbd73b6
MD5 0ef18c58cb8166020bd93d1f50b539b3
BLAKE2b-256 61dc67be6b61a838eb2017aa6204346713296e9351e4d783ec3507de94a1f4db

See more details on using hashes here.

Supported by

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