mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-04-25 03:32:55 +03:00
added ability to deserialize string value
This commit is contained in:
parent
fc80462ce7
commit
f1798b0cc6
@ -1,3 +1,5 @@
|
||||
from typing import Union
|
||||
|
||||
from django.conf import settings
|
||||
from django.db.utils import IntegrityError
|
||||
from django.utils import six, translation
|
||||
@ -114,7 +116,7 @@ class LocalizedField(HStoreField):
|
||||
|
||||
return cls.attr_class(value)
|
||||
|
||||
def to_python(self, value: dict) -> LocalizedValue:
|
||||
def to_python(self, value: Union[dict, str, None]) -> LocalizedValue:
|
||||
"""Turns the specified database value into its Python
|
||||
equivalent.
|
||||
|
||||
@ -127,7 +129,8 @@ class LocalizedField(HStoreField):
|
||||
A :see:LocalizedValue instance containing the
|
||||
data extracted from the database.
|
||||
"""
|
||||
|
||||
# make deserialization if need by parent method
|
||||
value = super(LocalizedField, self).to_python(value)
|
||||
if not value or not isinstance(value, dict):
|
||||
return self.attr_class()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user