Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to support JSONField #26

Open
lucas-bremond opened this issue Apr 22, 2020 · 1 comment
Open

How to support JSONField #26

lucas-bremond opened this issue Apr 22, 2020 · 1 comment

Comments

@lucas-bremond
Copy link

lucas-bremond commented Apr 22, 2020

I've tried the following:

from django.contrib.postgres.fields import JSONField
from fernet_fields import EncryptedField

class EncryptedJSONField (EncryptedField, JSONField):
    ...

private_column = EncryptedJSONField(default = dict)

but got the following error:

django.db.utils.ProgrammingError: column "private_column" is of type jsonb but expression is of type bytea

Any suggestion?

@marcus-campos
Copy link

marcus-campos commented Jun 6, 2020

@lucas-bremond I managed to solve this way, I don't know if it's the best way, but it worked for me

from fernet_fields import EncryptedField

from django.contrib.postgres.fields import JSONField


class CustomJSONField(JSONField):
    def db_type(self, connection):
        return 'text'


class JSONEncryptedField(EncryptedField, CustomJSONField):
    pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants