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
The ugly:
import random
From the documentation:
This module implements pseudo-random number generators for various distributions.
If anything, please use os.urandom
Return a string of n random bytes suitable for cryptographic use.
This is how I use it in my models:
import os
from binascii import hexlify
def _createId():
return hexlify(os.urandom(16))
class Book(models.Model):
id_book = models.CharField(max_length=32, primary_key=True, default=_createId)