I need to add slug field to django model, and i thing it's better when it not null. So i'm trying to add slug to model
slug = models.SlugField(
'URL',
unique=True,
default=id_generator,
)
my id_generator:
import string
import random
def id_generator():
size=16
chars=string.ascii_lowercase + string.digits
return ''.join(random.choice(chars) for x in range(size))
The problem is when i migrate changes. Method id_generator is calling one time and uses the same value for all model objects. So i have dupliicate entrie in unique field. How can i generate unique values? Django 1.11.5
P.S. I understand, that i can set null=True and customize model's save method to add slug when saving.