Metadata-Version: 2.4
Name: apis-datamodel
Version: 0.1.0
Summary: Datamodel showing entities and relationships
Project-URL: Homepage, https://github.com/gythaogg/apis-datamodel
Author: Saranya Balasubramanian
License: MIT
Keywords: datamodel,entities,relationships
Classifier: Framework :: Django
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.13
Requires-Dist: apis-core-rdf>=0.62.0
Provides-Extra: dev
Description-Content-Type: text/markdown

# apis-datamodel

A reusable Django app that introspects your [APIS Core](https://github.com/acdh-oeaw/apis-core-rdf) data model and displays a matrix of relations between entity types.

## Features

- Automatically discovers all `Relation` subclasses defined in your project
- Renders a subject × object matrix where each cell shows the `name` and `reverse_name` of the relation
- Overridable templates via Django's standard app template loading order
- Django system checks to catch missing dependencies and misconfigured `INSTALLED_APPS` / URL includes early

## Requirements

- Python ≥ 3.13
- Django (any version supported by `apis-core-rdf`)
- `apis-core-rdf >= 0.62.0`

## Installation

```bash
pip install apis-datamodel
```

## Setup

### 1. Add to `INSTALLED_APPS`

`apis_datamodel` must appear **after** your project app so project-level template overrides are discovered first:

```python
INSTALLED_APPS = [
    ...
    "apis_core.apis_metainfo",
    "apis_core.relations",
    "apis_core.apis_entities",
    "your_project",   # must come before apis_datamodel
    "apis_datamodel",
]
```

### 2. Include the URLs

```python
# urls.py
from django.urls import include, path

urlpatterns = [
    ...
    path("datamodel/", include("apis_datamodel.urls")),
]
```

The matrix view is then available at `/datamodel/`.

## Template customisation

The package ships with two templates:

| Template | Purpose |
|---|---|
| `apis_datamodel/base.html` | Wrapper — provides `dm_head` and `dm_content` blocks |
| `apis_datamodel/datamodel.html` | Renders the relation matrix |

To customise the layout, place a file at the same path inside your own app's `templates/` directory. Because your app is listed before `apis_datamodel` in `INSTALLED_APPS`, Django will pick yours up first.

The package template for `datamodel.html` extends `apis_datamodel/base.html` by default, but you can point it at your own base template by passing a `parent_template` context variable:

```python
# e.g. in a subclassed view
def get_context_data(self, **kwargs):
    ctx = super().get_context_data(**kwargs)
    ctx["parent_template"] = "base.html"
    return ctx
```

## System checks

The app registers three Django system checks that run with `manage.py check`:

| ID | What it validates |
|---|---|
| `apis_datamodel.E001` | Required APIS Core apps are present in `INSTALLED_APPS` |
| `apis_datamodel.E002` | `apis_datamodel.urls` is included in the root URLconf |
| `apis_datamodel.E003` | `apis_datamodel` appears after the host project app in `INSTALLED_APPS` |

## License

MIT

