mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-10-29 18:18:57 +03:00
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:
@@ -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.
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user