# Models

> Everything Cloud Management Platform (CMP) manages is a Django model, accessed through the same ORM CMP uses

---

Site [llms.txt](/llms.txt)

---

CMP is a [Django](https://www.djangoproject.com/) application, and its data is stored in a PostgreSQL database via Django's [object-relational mapper](https://docs.djangoproject.com/en/stable/topics/db/models/). Change objects through the ORM rather than in SQL: CMP's business logic runs on create and change, and a direct `UPDATE` skips it.

## Explore the models

- **[Shell Plus](/docs/cmp/developer-resources/guide/shell-plus/)** opens a Python shell with every model imported, and you can use tab completion to list an object's fields and methods. Getting comfortable with it pays off when you start writing plugins.
- **[Use Django ORM](/docs/cmp/use/orchestration/plugins/django-orm/)** covers querying and updating objects from a plugin, including key query patterns.
- **Admin** > **API Browser** lists the objects and operations that CMP exposes via [the REST API](/docs/cmp/developer-resources/rest-api/), which is a useful cross-check for names and relationships.

## Generate a database diagram

CMP ships with the `graph_models` management command, which renders an entity-relationship diagram for one or more Django apps. The CMP schema is too large to fit in a single image; generate one app at a time.

### Install the diagram tools

Rendering to an image needs Graphviz and PyDotPlus. Install them as the root user on the CMP appliance.

```bash
sudo su -
yum install -y graphviz
pip install pydotplus
```

### Generate the diagram

Start by determining which app owns your target model. An app label is the name of the model's package: `Server` lives in `infrastructure`, `ResourceHandler` in `resourcehandlers`, `OSBuild` in `externalcontent`. In Shell Plus, `Server._meta.app_label` returns the label for any model.

Then generate the file. The output format follows the file extension you give `--output`. This example writes the infrastructure app's schema to `infrastructure.pdf` in the current directory. Copy the file from the appliance with `scp` or a similar tool to view it.

```bash
/opt/cloudbolt/manage.py graph_models -t original --output infrastructure.pdf infrastructure
```

Pass several app labels to draw them on one diagram.

---

Section pages:

- [Resource handler model](/docs/cmp/developer-resources/guide/models/resource-handlers/): A resource handler holds the connection to a cloud or hypervisor and pairs it with the Python class that makes the API calls
- [Environment model](/docs/cmp/developer-resources/guide/models/environments/): An environment is the target into which a server or resource is provisioned, and the model that ties a resource handler to the groups, images, and parameters associated with it
- [OS build model](/docs/cmp/developer-resources/guide/models/os-builds/): An OS build names an operating system once, then maps that name to the image or template each resource handler needs
- [Orders and jobs](/docs/cmp/developer-resources/guide/models/orders-and-jobs/): An order is what a user submits; a job is what the job engine runs to fulfill one item of it
