Add experimental features flag for LocalizedField

With the flag set, LocalizedField will return None if there is no
database value.
This commit is contained in:
Bogdan Hopulele
2017-03-23 17:32:26 +02:00
parent 5df44b0d62
commit 52145ca7d3
5 changed files with 35 additions and 7 deletions

View File

@@ -1,8 +1,8 @@
from django.conf import settings
from django.db.utils import IntegrityError
from psqlextra.fields import HStoreField
from localized_fields import LocalizedFieldForm
from psqlextra.fields import HStoreField
from ..localized_value import LocalizedValue
@@ -36,11 +36,15 @@ class LocalizedField(HStoreField):
"""
if not value:
return LocalizedValue()
if getattr(settings, 'LOCALIZED_FIELDS_EXPERIMENTAL', False):
return None
else:
return LocalizedValue()
return LocalizedValue(value)
def to_python(self, value: dict) -> LocalizedValue:
@staticmethod
def to_python(value: dict) -> LocalizedValue:
"""Turns the specified database value into its Python
equivalent.

View File

@@ -15,7 +15,7 @@ class LocalizedModel(PostgresModel):
Here we set all the fields that are of :see:LocalizedField
to an instance of :see:LocalizedValue in case they are none
so that the user doesn't explicitely have to do so."""
so that the user doesn't explicitly have to do so."""
super(LocalizedModel, self).__init__(*args, **kwargs)