If you need to modify instance fields depending on the instance’s pk or id, hop on.
When you create an instance, before it is saved, you can’t have pk or id as it is not yet created.
def save(self, *args, **kwargs):
# self.pk == None
# self.id == None
super().save(*args, **kwargs)
# self.pk != None
# self.id != None
If you have a property that somehow depends on the value of self.pk or self.id and you want to have it saved on creating, you have two options.
Read More »