I am trying to add a hashid that is based on the pk of my model
class ExampleModel(models.Model):
hash_id = models.CharField(max_length=30)
How the hash_id is created.. Assume 15454 is the pk of my object.
from hashids import Hashids
hashids = Hashids(salt='example salt')
hashids.encode(15454)
'Eo6v'
The main reason I want to store the hash_id in the model is because I don't want to recompute it everytime or if my salt changes in the future for some reason.
Is there a way to automatically generate this field when the object is created since it needs the PK to be created first?