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-1.0.0.tar.gz (5.9 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-1.0.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_namedid-1.0.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_namedid-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b5a4e78f263b13fcfb40acc8439dd420ce4f01eec874368466f6659d217979af
MD5 559b2b29c5e36a916f0a48b585ca1f66
BLAKE2b-256 56af06e867f9f6c68e77c518888cf9ea7dc59f14ef63d2fb14eec848845252e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_namedid-1.0.0.tar.gz:

Publisher: release.yml on octolo/django-namedid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: django_namedid-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_namedid-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35d5b3ec8458da4424a9c111432ed92f7e63b27a90c128f663d67981cc0aa529
MD5 4a18054192f1f543e2b01e3378fa87ac
BLAKE2b-256 b0cd1eb34109df98968f54631ad8a3a5a386b9bab865e30e096301175315ef1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_namedid-1.0.0-py3-none-any.whl:

Publisher: release.yml on octolo/django-namedid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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