One model field map to two database columns

34 views
Skip to first unread message

Dann Luciano

unread,
Aug 22, 2022, 11:26:15 AM8/22/22
to Django users
Hi everyone,

It is possible to map one field in a Model to two or more database columns? For example:

class User(models.Model):
    encrypted_hash_email = EncryptedHash()

then in database we have

encrypted_email and hash_email columns?

Thanks and have a good day!

Ryan Nowakowski

unread,
Aug 23, 2022, 9:29:59 AM8/23/22
to Django users
On Mon, Aug 22, 2022 at 05:56:00AM -0700, Dann Luciano wrote:
> It is possible to map one field in a Model to two or more database columns?
> For example:
>
> class User(models.Model):
> encrypted_hash_email = EncryptedHash()
>
> then in database we have
>
> encrypted_email and hash_email columns?

The django-money package stores the value in a DecimalField and the
currency in a CharField but abstracts both behind a single MoneyField[1].

[1] https://github.com/django-money/django-money/blob/main/djmoney/models/fields.py#L168

Dann Luciano

unread,
Aug 25, 2022, 3:50:56 PM8/25/22
to Django users
Thanks Ryan.
Reply all
Reply to author
Forward
0 new messages