Skip to main content

A drop-in replacement for django-hashid-field with Django 5.x/6.x support

Project description

shopcloud-django-hashid

A drop-in replacement for django-hashid-field with Django 5.x and 6.x support.

Features

  • Drop-in compatible: Same import paths and API as django-hashid-field
  • Django 5.x/6.x support: Designed for modern Django versions
  • Zero migration effort: Existing migrations work without changes
  • Identical hashid output: Same salt produces same hashids
  • Full ORM support: Works with all Django ORM operations
  • Django REST Framework integration: Automatic serialization support
  • Thread-safe: Safe for concurrent use in production

Installation

pip install shopcloud-django-hashid

Migration from django-hashid-field

pip uninstall django-hashid-field
pip install shopcloud-django-hashid

No code changes required. Your existing imports continue to work:

from hashid_field import HashidField, HashidAutoField
from hashid_field import BigHashidField, BigHashidAutoField
from hashid_field import Hashid

Verify no migrations are needed:

python manage.py makemigrations --dry-run
# Should output: "No changes detected"

Quick Start

Model Definition

from django.db import models
from hashid_field import HashidAutoField, HashidField

class Article(models.Model):
    id = HashidAutoField(primary_key=True)
    title = models.CharField(max_length=200)

class Comment(models.Model):
    id = HashidAutoField(primary_key=True)
    article = models.ForeignKey(Article, on_delete=models.CASCADE)
    reference_code = HashidField()  # Non-primary key hashid

Django Settings

# settings.py

# Required: Set your salt (keep secret!)
HASHID_FIELD_SALT = "your-secret-salt-here"

# Optional: Customize defaults
HASHID_FIELD_MIN_LENGTH = 7
HASHID_FIELD_ALLOW_INT_LOOKUP = False

Usage

# Create
article = Article.objects.create(title="Hello World")
print(article.id)        # Hashid('kRm4x7')
print(str(article.id))   # 'kRm4x7'
print(int(article.id))   # 1

# Query by hashid string
article = Article.objects.get(pk='kRm4x7')

Field Types

Field Base Use Case
HashidField IntegerField General hashid storage
BigHashidField BigIntegerField Large integer hashids
HashidAutoField AutoField Primary key with hashid
BigHashidAutoField BigAutoField Big auto primary key

Settings

Setting Default Description
HASHID_FIELD_SALT "" Global salt for encoding
HASHID_FIELD_MIN_LENGTH 7 Minimum hashid length
HASHID_FIELD_ALLOW_INT_LOOKUP False Allow integer-based queries
HASHID_FIELD_ENABLE_HASHID_OBJECT True Return Hashid objects vs strings

Django REST Framework

If DRF is installed, HashidFields serialize automatically:

from rest_framework import serializers
from .models import Article

class ArticleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Article
        fields = ['id', 'title']
    # id will serialize as hashid string, e.g., "kRm4x7"

Requirements

  • Python 3.12+
  • Django 5.0+
  • hashids >= 1.3.1

Publishing to PyPI (Maintainers)

This package uses PyPI Trusted Publishing for secure, token-free releases:

  1. Configure Trusted Publisher on PyPI:

    • Log in to pypi.org
    • Go to your account → Publishing → Add a new trusted publisher
    • Set repository owner, name, and workflow file (publish.yml)
  2. Create a Release:

    • Update version in pyproject.toml and hashid_field/__init__.py
    • Update CHANGELOG.md
    • Create a GitHub Release with a tag (e.g., v0.1.0)
    • The GitHub Action will automatically publish to PyPI

License

MIT License - see LICENSE for details.

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

shopcloud_django_hashid-0.4.0.tar.gz (29.0 kB view details)

Uploaded Source

Built Distribution

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

shopcloud_django_hashid-0.4.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file shopcloud_django_hashid-0.4.0.tar.gz.

File metadata

  • Download URL: shopcloud_django_hashid-0.4.0.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for shopcloud_django_hashid-0.4.0.tar.gz
Algorithm Hash digest
SHA256 ff6d14acfce5c875d36b3e5d303c383660ae00b3b030ce9d3229ff37f253cc2e
MD5 ac912a0196facf855d4a39c3fa21f4a8
BLAKE2b-256 d6f48da77c3422f3471477741c7f335e74fb88afb5867b73a8f715b63215d0e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for shopcloud_django_hashid-0.4.0.tar.gz:

Publisher: publish.yml on Talk-Point/shopcloud-django-hashid

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

File details

Details for the file shopcloud_django_hashid-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for shopcloud_django_hashid-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a442d23fadaf776a49563369cd0c64d302213e39b8dcc7c1d721463f3113ae17
MD5 085526a925e35daf9e5d04a256b5eed1
BLAKE2b-256 c0ba2d09cbea0d25e89a1a42f3b8597e532481485fbbae0774cd3f27de855f57

See more details on using hashes here.

Provenance

The following attestation bundles were made for shopcloud_django_hashid-0.4.0-py3-none-any.whl:

Publisher: publish.yml on Talk-Point/shopcloud-django-hashid

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