In Django 4 custom model save() method, how do you pass a form non-persistent form value?
For example:
The model form below has the non-persistent field called client_secret.
class ClientModelForm(forms.ModelForm):
client_secret = forms.CharField(initial=generate_urlsafe_uuid)
This field will never be saved, it is auto-generated and will be required to make a hash for a persisted field in my model save() method.
class Client(models.Model):
client_hash = models.BinaryField(editable=False, blank=True, null=True)
def save(self, *args, **kwargs):
""" Save override to hash the client secret on creation. """
if self._state.adding:
"GET THE CLIENT SECRET FROM THE FORM"
client_hash = make_hash_key(client_secret)
self.client_hash = client_hash
How do I get the client secret value from the form above code example? Is this the most appropriate approach?