Metadata-Version: 2.3
Name: mcms-content
Version: 0.1.0
Summary: It provides a canonical MCMS representation of fields while allowing Django to remain the source of truth for database structure and persistence
Author: MikemathuKE
Author-email: MikemathuKE <michaelmathu6@gmail.com>
Requires-Dist: django>=6.0.7
Requires-Dist: mcms-core
Requires-Python: >=3.13
Description-Content-Type: text/markdown

# MCMS Content

`mcms_content` defines MCMS-specific content field semantics for Django models. It provides a canonical MCMS representation of fields while allowing Django to remain the source of truth for database structure and persistence.

## Responsibilities

- Define the canonical MCMS `FieldDefinition` representation.
- Derive MCMS field definitions from Django model fields and optional MCMS-specific model configuration.
- Inspect Django model metadata through `Model._meta`.
- Support MCMS-specific field metadata, such as editor widgets and CMS capabilities.
- Validate MCMS field configuration against corresponding Django model fields.
- Provide a consistent field representation for editor behaviour, validation, serialization, documentation, and other MCMS features.

## Architecture decision

Django model definitions remain authoritative for database schema and persistence. Django migrations continue to manage database changes.

`FieldDefinition` is the canonical representation of field semantics within MCMS; it is not a replacement for Django model fields and does not generate the database schema.

MCMS derives field definitions by inspecting Django model metadata and combining it with optional MCMS-specific configuration declared on the model.

```text
Django Model
    |
    | Model._meta
    |
    +--> Django Field Metadata
    |
    +--> Optional MCMS Configuration
              |
              v
       Field Definition Resolution
              |
              v
        FieldDefinition
              |
              +--> MCMS Editor and CMS Capabilities
```

## Avoid duplicating Django metadata

MCMS should derive properties already available from Django rather than requiring developers to declare them again.

Examples include:

- Primary-key status.
- Nullability.
- Defaults.
- Uniqueness.
- Maximum length.
- Database indexes and constraints, where applicable.

MCMS metadata should describe CMS-specific behaviour, for example:

- Editor widget and widget configuration.
- Searchable or sortable capabilities.
- CMS-specific validation and behaviour.
- Serialization hints.
- Documentation metadata.

MCMS should use appropriate defaults when optional MCMS metadata is absent.

MCMS-specific configuration must not override database-level constraints or persistence behaviour defined by Django.

## Example

The following is illustrative of the intended relationship; use the actual field constructors and metadata API implemented by this package.

```python
from django.db import models


class Article(models.Model):
    title = models.CharField(max_length=255)
    body = models.TextField()

    class MCMS:
        # MCMS-specific field metadata belongs here.
        ...
```

The Django fields continue to define the database columns. MCMS inspects the Django model fields and any supported MCMS metadata to derive normalized `FieldDefinition` objects.

## Architectural integrations

| Package / system | Relationship |
|---|---|
| Django models | Source of truth for database fields and persistence |
| `mcms_core` | Shared domain infrastructure and common exception conventions |

`mcms_content` maintains the separation between Django persistence definitions and MCMS field semantics. Field definition resolution does not generate Django model fields or manage database schema.

Confirm direct imports and declared package dependencies in the implementation.

## Application configuration

This package contains a field registry which holds MCMS field types registered for use within the package.

The registry provides access to registered MCMS field types and their definitions.

## Dependencies

### Architectural integrations

Django model metadata and optional MCMS model configuration are inputs to field definition resolution. MCMS field semantics are the resulting normalized representation.

The package must not become the owner of Django database schema or migrations.

### Python distribution dependencies

MCMS packages rely on Django.

## Development

```bash
uv run pytest packages/mcms-content/tests
```

Run the repository-configured Ruff and mypy checks where applicable.
