[Django]-UUID as default value in Django model

36👍

Problem is the default attribute that you are setting as

activation_key = models.CharField(max_length=64, verbose_name=u"Activation key",
                 default=uuid.uuid1())

Here you are setting the default value as not a callable but value returned by uuid.uuid1() call when this model class is initialized.

You should set it as default=uuid.uuid1 which sets it as callable, and is sets new uuid each time new default value needs to be used.

👤Rohan

13👍

As of Django 1.8, there is a new UUIDField available. It’s described in the following link which also covers how to set defaults:

https://docs.djangoproject.com/en/1.8/ref/models/fields/#uuidfield

Leave a comment