1

I have a custom field:

class MyCustomTextField(models.Field):
(...)

and use that on my model:

class MyModel():
  encrypted_password = MyCustomTextField(null=True)
  password_seed = models.TextField(null=True)

I need when I use MyModel to grab encrypted_password, I need to grab first password_seed and return a new value using the password_seed value.

How can I do that, since custom model is instantiate before the data comes to the model?

fh_bash
  • 1,725
  • 4
  • 16
  • 23
  • You can override save method and add the logic you need. – ariaman5 Jun 17 '21 at 18:20
  • @ariaman5 I'm looking for something more "wide", into the custom field class, so I can use it for all models, overriding the save method, I need to do it for each model I use – fh_bash Jun 17 '21 at 18:46
  • Does other models have encrypted_password and password_seed too? I think it has nothing to do with the custom field. Maybe you can use inheritance for the models. – ariaman5 Jun 18 '21 at 06:06
  • Yeah, all inherited models have those fields. But I think I need something "general" not one by one (models) – fh_bash Jun 21 '21 at 10:33

1 Answers1

0

read this article from Django docs. you should override the method

def deconstruct(self): ...

of MyCustomTextField