django_mycelium/translatable_fields/models.py
2018-03-08 18:22:58 +03:00

26 lines
603 B
Python

from django.contrib.postgres.fields import JSONField
from translatable_fields.value import TranslatableValue
class TranslatableField(JSONField):
def from_db_value(self, value, *args, **kwargs):
if value is None:
return value
instance = TranslatableValue()
instance.update(value)
return instance
def to_python(self, value):
if isinstance(value, TranslatableValue):
return value
if value is None:
return value
instance = TranslatableValue()
instance.update(value)
return instance