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

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_namedid-0.2.1.tar.gz
  • Upload date:
  • Size: 5.4 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.1.tar.gz
Algorithm Hash digest
SHA256 351f90201bd3351d95d21d5850c97f70398d0b9cb9c13853c39d10d27f21ebfa
MD5 4fdb8638d57981b8ebc39c9dd40e9f65
BLAKE2b-256 b69ea57c5b9c4723341aa7277128ec002a687b0237e90c373f752d3359f07473

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_namedid-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c15658f9c963de4777c68da1ebd46baed995aac8fed0c6c74925c2b204a00105
MD5 7e01847adf5506d40e5cb9831f528ac5
BLAKE2b-256 05d5a02f51e10ca484d7c52b66ca476c52b7ceea5679510cc5ffa16e802e483a

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