1👍
✅
That’s not where you would do it. You can’t write something at the class level that depends on an instance attribute of the class: it’s simply not possible. And what’s more, a default is allocated when the object is instantiated, but you want that to change after the user has changed the value of another attribute, so this isn’t a default at all.
Instead you probably want to define this value on save. That’s easy to do by simply overriding the save
method:
def save(self, *args, **kwargs):
if not self.uid:
self.uid = str(shortuuid.uuid(name=self.user))
return super(website, self).save(*args, **kwargs)
Source:stackexchange.com