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 model | app_label | model |
|---|---|---|
| AllergyIntolerance | api | allergyintolerance |
| Appointment | api | appointment |
| Assessment | api | assessment |
| BannerAlert | api | banneralert |
| ChartSectionReview | api | chartsectionreview |
| Condition | api | condition |
| Coverage | api | coverage |
| DetectedIssue | api | detectedissue |
| Device | api | device |
| DiagnosticReport | api | diagnosticreport |
| DocumentReference | api | documentreference |
| Encounter | api | encounter |
| Facility | api | facility |
| Goal | api | goal |
| ImagingOrder | api | imagingorder |
| ImagingReport | api | imagingreport |
| ImagingReview | api | imagingreview |
| Immunization | api | immunization |
| Instruction | api | instruction |
| Interview | api | interview |
| LabOrder | api | laborder |
| LabReport | api | labreport |
| LabValue | api | labvalue |
| Letter | api | letter |
| Medication | api | medication |
| MedicationStatement | api | medicationstatement |
| Message | api | message |
| Note | api | note |
| Observation | api | observation |
| Organization | api | organization |
| Patient | api | patient |
| PatientConsent | api | patientconsent |
| PatientGroup | api | patientgroup |
| PracticeLocation | api | practicelocation |
| Prescription | api | prescription |
| Questionnaire | api | questionnaire |
| ReasonForVisit | api | reasonforvisit |
| Referral | api | referral |
| Staff | api | staff |
| StopMedicationEvent | api | stopmedicationevent |
| Task | api | task |
| Team | api | team |
| UncategorizedClinicalDocument | api | uncategorizedclinicaldocument |
| VisualExamFinding | api | visualexamfinding |
Other apps #
Some models live in a different Django app, so their app_label is not api:
| SDK data model | app_label | model |
|---|---|---|
| Command | commands | command |
| Application | plugin_io | application |
| PluginCommand | plugin_io | plugincommand |
| Calendar | calendars | calendar |
| ExternalEvent | data_integration | externalevent |
| ServiceProvider | data_integration | serviceprovider |
| ChargeDescriptionMaster | quality_and_revenue | chargedescriptionmaster |
| Claim | quality_and_revenue | claim |
| PayorSpecificCharge | quality_and_revenue | payorspecificcharge |
Attributes #
ContentType #
| Field Name | Type |
|---|---|
| dbid | Integer |
| app_label | String |
| model | String |
- 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).