ContentType

Introduction #

The ContentType model provides read-only access to Django content types. Use it to resolve the content type id for a given model, which is required when working with generic relations (such as document references) and when generating permalinks.

A content type is identified by two stable values — app_label and model — that are the same on every Canvas instance. Its dbid (the content type id) is a per-database auto-increment that is not stable across environments. Always resolve the dbid at runtime from the app_label and model; never hardcode a content type id, or it will point at the wrong model in another environment.

Basic usage #

To get a content type by its database id, use the get method on the ContentType model manager:

from canvas_sdk.v1.data import ContentType

content_type = ContentType.objects.get(dbid=42)

Resolving a content type at runtime #

Because the dbid differs per environment, look the content type up by its stable app_label and model, then read dbid from the result:

from canvas_sdk.v1.data import ContentType

content_type = ContentType.objects.filter(app_label="api", model="note").first()
if content_type:
    # Resolved for this environment — safe to use for a generic relation or permalink.
    content_type_id = content_type.dbid

Filtering #

Content types can be filtered by any attribute that exists on the model.

Filtering for content types is done with the filter method on the ContentType model manager.

By model #

To find the content type for a specific model, filter by app_label and model:

from canvas_sdk.v1.data import ContentType

content_type = ContentType.objects.filter(app_label="api", model="note").first()
if content_type:
    print(f"Content type id: {content_type.dbid}")

app_label and model for data module models #

Use these stable values to resolve a content type with ContentType.objects.filter(app_label=..., model=...). The model value is the lowercased Django model name, and most data module models live under the api app. This list is not exhaustive — any model not shown here can be resolved the same way once you know its app_label and model.

api app #

SDK data modelapp_labelmodel
AllergyIntoleranceapiallergyintolerance
Appointmentapiappointment
Assessmentapiassessment
BannerAlertapibanneralert
ChartSectionReviewapichartsectionreview
Conditionapicondition
Coverageapicoverage
DetectedIssueapidetectedissue
Deviceapidevice
DiagnosticReportapidiagnosticreport
DocumentReferenceapidocumentreference
Encounterapiencounter
Facilityapifacility
Goalapigoal
ImagingOrderapiimagingorder
ImagingReportapiimagingreport
ImagingReviewapiimagingreview
Immunizationapiimmunization
Instructionapiinstruction
Interviewapiinterview
LabOrderapilaborder
LabReportapilabreport
LabValueapilabvalue
Letterapiletter
Medicationapimedication
MedicationStatementapimedicationstatement
Messageapimessage
Noteapinote
Observationapiobservation
Organizationapiorganization
Patientapipatient
PatientConsentapipatientconsent
PatientGroupapipatientgroup
PracticeLocationapipracticelocation
Prescriptionapiprescription
Questionnaireapiquestionnaire
ReasonForVisitapireasonforvisit
Referralapireferral
Staffapistaff
StopMedicationEventapistopmedicationevent
Taskapitask
Teamapiteam
UncategorizedClinicalDocumentapiuncategorizedclinicaldocument
VisualExamFindingapivisualexamfinding

Other apps #

Some models live in a different Django app, so their app_label is not api:

SDK data modelapp_labelmodel
Commandcommandscommand
Applicationplugin_ioapplication
PluginCommandplugin_ioplugincommand
Calendarcalendarscalendar
ExternalEventdata_integrationexternalevent
ServiceProviderdata_integrationserviceprovider
ChargeDescriptionMasterquality_and_revenuechargedescriptionmaster
Claimquality_and_revenueclaim
PayorSpecificChargequality_and_revenuepayorspecificcharge

Attributes #

ContentType #

Field NameType
dbidInteger
app_labelString
modelString
  • dbid: The internal database primary key, which is the content type id used for generic relations and permalinks. This value is environment-specific — resolve it at runtime rather than hardcoding it.
  • app_label: The label of the application the model belongs to (e.g., api).
  • model: The lowercased name of the model (e.g., note).