Skip to main content

SARS-COV-2 related models, etc

Project description

Add to an EDC

In this example we add the new model to the meta_subject app of the meta_edc project.

Add sarscov2 to your settings INSTALLED_APPS

INSTALLED_APPS = [
    ...
    "sarscov2.apps.AppConfig",
    ...
]

Use the model mixin to create the model in your app

from edc_crf.model_mixins import CrfModelMixin
from edc_model import models as edc_models

from sarscov2.model_mixins import CoronaKapModelMixin


class CoronaKap(CrfModelMixin, CoronaKapModelMixin, edc_models.BaseUuidModel):
    class Meta:
        verbose_name = "Corona Knowledge, Attitudes, and Practices"
        verbose_name_plural = "Corona Knowledge, Attitudes, and Practices"

Create a form using the CoronaKapFormValidator

from django import forms
from edc_crf.modelform_mixins import CrfModelFormMixin
from sarscov2.forms import CoronaKapFormValidator

from ..models import CoronaKap


class CoronaKapForm(CrfModelFormMixin, forms.ModelForm):

    form_validator_cls = CoronaKapFormValidator

    class Meta:
        model = CoronaKap
        fields = "__all__"

Create an admin class with your new model and form. In this case the new model is a CRF model.

from django.contrib import admin
from edc_form_label import FormLabelModelAdminMixin
from edc_model_admin import SimpleHistoryAdmin
from sarscov2.admin import CoronaKapModelAdminMixin

from ..admin_site import meta_subject_admin
from ..forms import CoronaKapForm
from ..models import CoronaKap
from .modeladmin import CrfModelAdminMixin


@admin.register(CoronaKap, site=meta_subject_admin)
class CoronaKapAdmin(
    CrfModelAdminMixin,
    CoronaKapModelAdminMixin,
    FormLabelModelAdminMixin,
    SimpleHistoryAdmin,
):
    form = CoronaKapForm

Add the model to your auth codenames. For example, to the clinic group of meta_subject we added

# clinic group of codenames
# ...
"meta_subject.add_coronakap",
"meta_subject.change_coronakap",
"meta_subject.delete_coronakap",
"meta_subject.view_coronakap",
"meta_subject.view_historicalcoronakap",
"sarscov2.view_coronakapinformationsources",
# ...
# auditor group of codenames
# ...
"meta_subject.view_coronakap",
"meta_subject.view_historicalcoronakap",
# ...

Add the CRF to the visit schedule

Since the model is being added after the trial started, we add it to both the DAY1 visit CRFs and the PRN CRFs.

crfs_prn = FormsCollection(
    ...
    Crf(show_order=70, model="meta_subject.coronakap"),
    name="prn",
)

crfs_d1 = FormsCollection(
    ...
    Crf(show_order=70, model="meta_subject.coronakap"),
    name="day1",
)

If you are using the list model, add to urls

from sarscov2.admin_site import sarscov2_admin

...
path("admin/", sarscov2_admin.urls),
path("sarscov2/", include("sarscov2.urls")),
...

run makemigrations and migrate.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

sarscov2-0.1.8-py3-none-any.whl (41.7 kB view hashes)

Uploaded Python 3

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