Metadata-Version: 2.4
Name: django-namedid
Version: 0.2.2
Summary: Django field that combines multiple fields into a unique identifier with collision handling
Author-email: Octolo <dev@octolo.tech>
License-Expression: MIT
Project-URL: Homepage, https://github.com/octolo/django-namedid
Project-URL: Repository, https://github.com/octolo/django-namedid
Project-URL: Documentation, https://github.com/octolo/django-namedid#readme
Project-URL: Issues, https://github.com/octolo/django-namedid/issues
Keywords: django,django-field,unique-identifier,composite-field,named-id,slug-generation,django-orm,python
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Framework :: Django
Classifier: Framework :: Django :: 3.2
Classifier: Framework :: Django :: 4.0
Classifier: Framework :: Django :: 4.1
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Django>=3.2
Provides-Extra: dev
Requires-Dist: pytest>=8.3; extra == "dev"
Requires-Dist: pytest-django>=4.5; extra == "dev"
Requires-Dist: ruff>=0.5; extra == "dev"
Requires-Dist: mypy>=1.0; extra == "dev"
Requires-Dist: django-stubs>=5.0.0; extra == "dev"
Dynamic: license-file

# django-namedid

Django field that automatically combines multiple fields into a unique identifier with collision handling.

## Purpose

Create unique identifiers by combining multiple model fields (e.g., name, id, date) with automatic collision resolution.

## Installation

```bash
pip install django-namedid
```

## Quick Start

### Using NamedIDField directly

```python
from django.db import models
from namedid import NamedIDField
from datetime import date

class Product(models.Model):
    name = models.CharField(max_length=100)
    code = models.IntegerField()
    created_date = models.DateField()
    
    named_id = NamedIDField(
        source_fields=["name", "code", "created_date"],
        max_length=200,
    )
```

### Using the decorator

```python
from django.db import models
from namedid import add_namedid

@add_namedid(named_id=["title", "id"], slug=["title", "category"])
class Article(models.Model):
    title = models.CharField(max_length=200)
    category = models.CharField(max_length=50)
    content = models.TextField()
```

## Features

- **Automatic generation**: Values are generated automatically before saving
- **Collision handling**: Automatically appends numeric suffix if value exists (e.g., `name-1-2023`, `name-1-2023-1`, `name-1-2023-2`)
- **Type formatting**: Automatically formats dates, numbers, booleans
- **Unique and required**: Fields are always unique and cannot be empty
- **Read-only**: Fields are automatically set to read-only

## Field Properties

- `unique=True`: Always unique
- `editable=False`: Always read-only
- `blank=False`: Cannot be empty
- `null=False`: Cannot be NULL

## Development

```bash
./service.py dev install-dev
./service.py dev test
```

## License

MIT
