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

encode and decode json so JSONField is happy #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions translatable_fields/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.postgres.fields import JSONField
import json
from django.db.models import JSONField

from translatable_fields.value import TranslatableValue

Expand All @@ -9,7 +10,7 @@ def from_db_value(self, value, *args, **kwargs):
return value

instance = TranslatableValue()
instance.update(value)
instance.update(json.loads(value))

return instance

Expand Down
2 changes: 1 addition & 1 deletion translatable_fields/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def value_from_datadict(self, data, files, name):
])
if all(map(lambda x: x == '', result.values())):
return ''
return result
return json.dumps(result)

def get_context(self, name, value, attrs):
context = super(forms.MultiWidget, self).get_context(name, value, attrs)
Expand Down