I have a text field in the model. Which holds the encrypted string in that field. Also, I have 2 functions in the DB to Encrypt and Decrypt. So, I want to wrap these DB functions on top of that field and save the encrypted string in the DB and while retrieving decrypt function should be wrapped on that field, and the object should have the decrypted string in that attribute.
I am thinking of using the Custom Field in Django. Please suggest to me how to do that?
class User(models.model):
name = models.CharField()
age = models.IntegerField()
email = models.TextField()
for example, let's take the email field, I want to have an encrypted string in that text field.
Let's take DB functions encrypt_email, decrypt_email
when I am running the following
user_objects= User.objects.filter(age__gt = 20)
It should run the query like as follows
SELECT *, decrypt_email(email) as email FROM users where age > 20;
Also when Inserting it should run the query as follows
INSERT INTO users (name, age, email) VALUES ('Rafiu', 25, encrypt_email('abc@gmail.com'));