I’d like to make a custom save method on a model that combines values from two of it’s other fields, one of which is a value stored in a foreign key relation.
For instance, given this model:
class Post(models.Model):
text = charfield()
date = datefield()
user = ForeignKey(other model)
key = integerfield()
unique = charfield()
I’d like to be able to save the field titled unique as a combination of both the user username from the foreign key, and the key field, which is an auto-incrementing integer field. Is something like this possible? I searched for similar questions but couldn’t find any.
The thing is of course that you won’t have a key until you’ve saved the model at least once. So your save method will need to call the superclass save, get the key, set the unique field, then save again.