I want to use unique hashes for each model rather than ids.
I implemented the following function to use it across the board easily.
import random,hashlib
Django 1.8+ has a built-in UUIDField
. Here's the suggested implementation, using the standard library's uuid
module, from the docs:
import uuid
from django.db import models
class MyUUIDModel(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
# other fields
For older django versions you can use the django-uuidfield package.