I'm trying to overwrite the pk of my models to use a random generator.
Here's the model field:
pk = models.AutoField(auto_created=True, primary_key=True, verbose_name='ID', default=genkey)
and the keygenerator:
def genkey():
return random.randrange(1,142857)
So, I would like to make the autofield to execute the genkey
function as much as possible until it gets a non-used key. Is there an attribute that I didn't find or do I need to code it in the generator (by getting all the used keys) ?
My main goal is to make a generator as generic as possible, not define a custom generator for each model.