I'm trying to implement custom field in my model following the docs, My model is as follow:
class User(AbstractUser):
uid = models.CharField(
"uid", max_length=255, null=True, blank=True)
phone_number = models.CharField(
"Phone number", max_length=255, null=True, blank=True)
nickname = models.CharField(
"Nickname", max_length=255, null=True, blank=True)
eth_address = models.CharField("Eth address", max_length=255, null=True, blank=True)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
# deleted
class eth_address_decrypted(models.Field):
description = 'eth_address_decrypted'
def __init__(self, *args, **kwargs):
return decrypt_string(self.eth_address)
class Meta:
db_table = "users"
pass
I have a eth_address
field that it's value are encrypted, i need to display the decrypted value on the frontend, so i wrote custom field model as the docs and call it on my front end through query:
User.objects.get(eth_address_decrypted=value)
But it returning the following error:
Cannot resolve keyword 'eth_address_decrypted' into field. Choices are: created, date_joined, email, eth_address,
What am i doing wrong ?
Is there a way i can call user.eth_address_decrypted
on object as a custom field or function without migrating it ? (because eth_address_decrypted just a convert from existed eth_adress)