Thursday, August 25, 2022

Re: One model field map to two database columns

Thanks Ryan.

On Tuesday, August 23, 2022 at 10:29:59 AM UTC-3 Ryan Nowakowski wrote:
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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/35469870-cefd-4f81-9740-e7bcaa4c91d1n%40googlegroups.com.

No comments:

Post a Comment