{"id":25927900,"url":"https://github.com/samirelanduk/django-random-id-model","last_synced_at":"2025-07-09T15:35:39.927Z","repository":{"id":57421491,"uuid":"312881216","full_name":"samirelanduk/django-random-id-model","owner":"samirelanduk","description":"A model base class which creates long, random, integer primary keys.","archived":false,"fork":false,"pushed_at":"2024-02-12T10:49:35.000Z","size":8,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T23:46:32.204Z","etag":null,"topics":["django","django-models","id-generator","primary-key"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samirelanduk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["samirelanduk"]}},"created_at":"2020-11-14T18:51:25.000Z","updated_at":"2025-01-28T13:06:29.000Z","dependencies_parsed_at":"2022-09-10T13:21:44.227Z","dependency_job_id":null,"html_url":"https://github.com/samirelanduk/django-random-id-model","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samirelanduk%2Fdjango-random-id-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samirelanduk%2Fdjango-random-id-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samirelanduk%2Fdjango-random-id-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samirelanduk%2Fdjango-random-id-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samirelanduk","download_url":"https://codeload.github.com/samirelanduk/django-random-id-model/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241739430,"owners_count":20012103,"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-models","id-generator","primary-key"],"created_at":"2025-03-03T21:11:03.676Z","updated_at":"2025-03-03T21:11:04.185Z","avatar_url":"https://github.com/samirelanduk.png","language":"Python","funding_links":["https://github.com/sponsors/samirelanduk"],"categories":[],"sub_categories":[],"readme":"# Django Random ID Model\n\nThis module provides a base class for Django models that gives them a random\nprimary key id.\n\nFor example, this is the vanilla way to do primary keys:\n\n```python\nfrom django.db import models\n\nclass Customer(models.Model):\n    name = models.CharField(max_length=50)\n\ncustomer1 = Customer.objects.create(name=\"John\")\ncustomer2 = Customer.objects.create(name=\"Jane\")\nprint(customer1.id) # '1'\nprint(customer2.id) # '2'\n```\n\nThe primary key just auto increments.\n\nNow use `RandomIDModel`:\n\n```python\nfrom django.db import models\nfrom django_random_id_model import RandomIDModel\n\nclass Customer(RandomIDModel):\n    name = models.CharField(max_length=50)\n\ncustomer1 = Customer.objects.create(name=\"John\")\ncustomer2 = Customer.objects.create(name=\"Jane\")\nprint(customer1.id) # '725393588906066'\nprint(customer2.id) # '905529381860540'\n```\n\nThe ID is guaranteed to be unique.\n\nBy default the ID will be 12 digits long, but you can override this in\nsettings.py with the `ID_DIGITS_LENGTH` setting.\n\n`RandomIDModel` inherits directly from `models.Model` and does not interfere\nwith anything else, so you can use it wherever you would use `models.Model`.\n\n## Forms and Admin\n\nTo integrate your model with a Django ModelForm, you will need to manually\nexclude the `id` field:\n\n```python\nfrom django.forms import ModelForm\n\nclass CustomerForm(ModelForm):\n\n    class Meta:\n        model = Customer\n        exclude = [\"id\"]\n```\n\nLikewise if you use the Django Admin app:\n\n```python\nfrom django.contrib import admin\n\nclass CustomerAdmin(admin.ModelAdmin):\n    exclude = [\"id\"]\n\nadmin.site.register(Customer, CustomerAdmin)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamirelanduk%2Fdjango-random-id-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamirelanduk%2Fdjango-random-id-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamirelanduk%2Fdjango-random-id-model/lists"}