There are similar questions but none recent and based on Django 3 so here it goes:
I am using py nanoid to generate some unique IDs so in my models I have
from nanoid import generate
and then
class Work(models.Model):
title = models.CharField(max_length=200)
body = models.TextField()
published = models.BooleanField(False)
date = models.DateTimeField()
nanoid = models.CharField(max_length=15, default = generate(size=10) )
def __str__ (self):
return self.title
my aim is to ensure that a new nanoid is generated each time a new work post is added. At the moment is the same repeated each time I try to add a new Work via admin.
I read some replies about creating a custom class but I am a bit at a loss here!