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

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_namedid-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 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.1.0.tar.gz
Algorithm Hash digest
SHA256 84a269deca8071c20f2d4592ae2622e53dd6a7a91543111ca2f6691b0ff53153
MD5 9da286818e6092d679086aeb8080104d
BLAKE2b-256 9229f1836661ebfc6588495d623fb90876b5ab77d2f2e1f469192fa7664c3ea0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_namedid-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4f8cffaabe8c224ac7ce2a5168434b0beaae3fd755cf982310eea858d77cb83
MD5 555847556a8cc6659f047000ba0d9bf8
BLAKE2b-256 a025acd0727c7110a4fbb3f783dd447800fb306d78a575fe202fd56d335e2cde

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