0

我正在尝试按照文档在我的模型中实现自定义字段,我的模型如下:

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

我有一个eth_address字段,它的值是加密的,我需要在前端显示解密的值,所以我将自定义字段模型编写为文档并通过查询在我的前端调用它:

User.objects.get(eth_address_decrypted=value)

但它返回以下错误:

Cannot resolve keyword 'eth_address_decrypted' into field. Choices are: created, date_joined, email, eth_address,

我究竟做错了什么 ?

有没有一种方法可以user.eth_address_decrypted在不迁移对象的情况下将对象作为自定义字段或函数调用?(因为 eth_address_decrypted 只是现有 eth_adress 的转换)

4

0 回答 0