{"id":14972784,"url":"https://github.com/ericls/django-hashids","last_synced_at":"2025-09-23T21:39:27.832Z","repository":{"id":39900050,"uuid":"275039283","full_name":"ericls/django-hashids","owner":"ericls","description":"Non-intrusive hashids library for Django","archived":false,"fork":false,"pushed_at":"2024-02-06T02:00:39.000Z","size":76,"stargazers_count":42,"open_issues_count":3,"forks_count":11,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-28T16:40:12.794Z","etag":null,"topics":["django","django-hashids","hacktoberfest","hashids"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericls.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-06-26T00:05:08.000Z","updated_at":"2024-07-03T03:28:02.000Z","dependencies_parsed_at":"2024-02-06T02:27:11.559Z","dependency_job_id":"8ea8794d-887a-447e-ac95-f7752e866f62","html_url":"https://github.com/ericls/django-hashids","commit_stats":{"total_commits":30,"total_committers":5,"mean_commits":6.0,"dds":"0.33333333333333337","last_synced_commit":"8bd37e65c65b444cbc38e2360dfbd499a4b0c877"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Fdjango-hashids","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Fdjango-hashids/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Fdjango-hashids/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericls%2Fdjango-hashids/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericls","download_url":"https://codeload.github.com/ericls/django-hashids/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219862132,"owners_count":16555959,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-hashids","hacktoberfest","hashids"],"created_at":"2024-09-24T13:47:32.072Z","updated_at":"2025-09-23T21:39:22.774Z","avatar_url":"https://github.com/ericls.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Django Hashids\n[![Github Actions](https://github.com/ericls/django-hashids/workflows/test/badge.svg)](https://github.com/ericls/django-hashids/actions)\n[![Code Coverage](https://codecov.io/gh/ericls/django-hashids/branch/master/graph/badge.svg)](https://codecov.io/gh/ericls/django-hashids)\n[![Python Version](https://img.shields.io/pypi/pyversions/django-hashids.svg)](https://pypi.org/project/django-hashids/)\n[![PyPI Package](https://img.shields.io/pypi/v/django-hashids.svg)](https://pypi.org/project/django-hashids/)\n[![License](https://img.shields.io/pypi/l/django-hashids.svg)](https://github.com/ericls/django-hashids/blob/master/LICENSE)\n\ndjango-hashids is a simple and non-intrusive hashids library for Django. It acts as a model field, but it does not touch the database or change the model.\n\n# Features\n- Proxy the internal model `pk` field without storing the value in the database.\n- Allows lookups and filtering by hashid string.\n- Can be used as sort key\n- Allows specifying a salt, min_length and alphabet globally\n- Supports custom salt, min_length, and alphabet per field\n- Supports Django REST Framework Serializers\n- Supports exact ID searches in Django Admin when field is specified in search_fields.\n- Supports common filtering lookups, such as __iexact, __contains, __icontains, though matching is the same as __exact.\n- Supports other lookups: isnull, gt, gte, lt and lte.\n\n# Install\n\n```bash\npip install django-hashids\n```\n\n`django-hashids` is tested with Django 1.11, 2.2, 3.0, 3.1, 3.2, 4.0 and python 3.6, 3.7, 3.8, 3.9, 3.10.\n\n# Usage\n\nAdd `HashidsField` to any model\n\n```python\nfrom django_hashids import HashidsField\n\nclass TestModel(Model):\n    hashid = HashidsField(real_field_name=\"id\")\n```\n\n`TestModel.hashid` field will proxy `TestModel.id` field but all queries will return and receive hashids strings. `TestModel.id` will work as before.\n\n## Examples\n\n```python\ninstance = TestModel.objects.create()\ninstance2 = TestModel.objects.create()\ninstance.id  # 1\ninstance2.id  # 2\n\n# Allows access to the field\ninstance.hashid  # '1Z'\ninstance2.hashid  # '4x'\n\n# Allows querying by the field\nTestModel.objects.get(hashid=\"1Z\")\nTestModel.objects.filter(hashid=\"1Z\")\nTestModel.objects.filter(hashid__in=[\"1Z\", \"4x\"])\nTestModel.objects.filter(hashid__gt=\"1Z\")  # same as id__gt=1, would return instance 2\n\n# Allows usage in queryset.values\nTestModel.objects.values_list(\"hashid\", flat=True) # [\"1Z\", \"4x\"]\nTestModel.objects.filter(hashid__in=TestModel.objects.values(\"hashid\"))\n\n```\n\n## Using with URLs\n\nYou can use hashids to identify items in your URLs by treating them as slugs.\n\nIn `urls.py`:\n\n```python\nurlpatterns = [\n    path(\"item/\u003cslug\u003e/\", YourDetailView.as_view(), name=\"item-detail\"),\n]\n```\n\nAnd in your view:\n\n```python\nclass YourDetailView(DetailView):\n    model = Item\n    slug_field = 'hashid'\n```\n\n## Config\n\nThe folloing attributes can be added in settings file to set default arguments of `HashidsField`:\n1. `DJANGO_HASHIDS_SALT`: default salt\n2. `DJANGO_HASHIDS_MIN_LENGTH`: default minimum length\n3. `DJANGO_HASHIDS_ALPHABET`: default alphabet\n\n`HashidsField` does not reqiure any arguments but the followinig arguments can be supplied to modify its behavior.\n\n| Name               |                        Description                        |\n| ------------------ | :-------------------------------------------------------: |\n| `real_field_name`  |                  The proxied field name                   |\n| `hashids_instance` | The hashids instance used to encode/decode for this field |\n| `salt`             |     The salt used for this field to generate hashids      |\n| `min_length`       |  The minimum length of hashids generated for this field   |\n| `alphabet`         |    The alphabet used by this field to generate hashids    |\n\nThe argument `hashids_instance` is mutually exclusive to `salt`, `min_length` and `alphabet`. See [hashids-python](https://github.com/davidaurelio/hashids-python) for more info about the arguments.\n\nSome common Model arguments such as `verbose_name` are also supported.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericls%2Fdjango-hashids","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericls%2Fdjango-hashids","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericls%2Fdjango-hashids/lists"}