Skip to main content

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

Project description

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

pip install django-namedid

Quick Start

Using NamedIDField directly

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

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

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

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_namedid-0.2.2.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_namedid-0.2.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file django_namedid-0.2.2.tar.gz.

File metadata

  • Download URL: django_namedid-0.2.2.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for django_namedid-0.2.2.tar.gz
Algorithm Hash digest
SHA256 5eb4d53d82268617a4164b452c739264d1eb7c5b0280e92d3056e62986077b5d
MD5 4ca43ed286e62af8d6029f520c151608
BLAKE2b-256 ba540fb1f6e361a4d9e71b2daea0c170e37fa212be96e2f5257977aa974f539d

See more details on using hashes here.

File details

Details for the file django_namedid-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: django_namedid-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for django_namedid-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3c60e0ef117ea66c70edac100b042967d900f2c54ce399cc1d65ac47213f4b8b
MD5 0eafd98dae974143a7917e7ae7317ede
BLAKE2b-256 c78943b8da9c319efa9ac4f579e94e9120ef052dbc89702f95f2a57512d22037

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page