I want to give a model field default value from the a model method.
How can i do that ?
when i try this code
Class Person(models.Model):
def create_id(self):
return os.urandom(12).encode('hex')
name = models.CharField(max_length = 255)
id = models.CharField(max_length = 255,default = self.create_id)
I get NameError: name 'self' is not defined.
If i remove the 'self' i get that 'create_id' needs 1 parameter.