This question already has answers here: How to create a GUID/UUID in Python (8 answers) Your post has been associated with a similar question. If this question doesn’t resolve your question, ask a new one.
Closed 8 mins ago.
(Private feedback for you)
I am generating a string using below technique but one thing I just want be sure of is that uniqueness of the string. will be a great help if anybody evaluate and suggest if there is a better way of getting a unique string.
models.py
import random
import string
def random_string_generator(size=10, chars=string.digits):
return ''.join(random.choice(chars) for _ in range(13))
class Orders(models.Model):
id= models.AutoField(primary_key=True)
token = models.CharField(max_length=13,
default=random_string_generator,
editable=False,
unique=True)
identifier = models.CharField(max_length=13,
default=random_string_generator,
editable=False,
unique=True)