I'm a little tricky with the new version of Django, the idea is to make an instance before you save and get the id or pk I repeat field without saving.
class User(models.Model):
.....
slug = models.SlugField(max_length=100, unique=True)
def save(self, *args, **kwargs):
"""
I'm need instance of user for access first self.pk
"""
self.slug = self.get_slug(self.pk)
return super(User, self).save()
The problem is still not defined "self.pk" alone will do it until you call save() that is until it is saved, the idea is to know how can I have the "self.pk" without saving earlier.
I think it could do so, but there is something wrong or not doing well, any ideas?
# My idea
def save(self, *ars, **kwargs):
instance = super(User, self).save()
self.slug = self.get_slug(self.pk)
return instance
Any idea?, thanks.