diff --git a/localized_fields/fields/field.py b/localized_fields/fields/field.py index 1047f0e..1817e7e 100644 --- a/localized_fields/fields/field.py +++ b/localized_fields/fields/field.py @@ -28,18 +28,26 @@ class LocalizedField(HStoreField): descriptor_class = LocalizedValueDescriptor def __init__( - self, *args, required: Union[bool, List[str]] = None, **kwargs + self, + *args, + required: Optional[Union[bool, List[str]]] = None, + blank: bool = False, + **kwargs ): """Initializes a new instance of :see:LocalizedField.""" - super(LocalizedField, self).__init__(*args, required=required, **kwargs) - - if (self.required is None and self.blank) or self.required is False: + if (required is None and blank) or required is False: self.required = [] - elif self.required is None and not self.blank: + elif required is None and not blank: self.required = [settings.LANGUAGE_CODE] - elif self.required is True: + elif required is True: self.required = [lang_code for lang_code, _ in settings.LANGUAGES] + else: + self.required = required + + super(LocalizedField, self).__init__( + *args, required=self.required, blank=blank, **kwargs + ) def contribute_to_class(self, model, name, **kwargs): """Adds this field to the specifed model. diff --git a/pytest.ini b/pytest.ini index 143a359..b1ab484 100644 --- a/pytest.ini +++ b/pytest.ini @@ -3,3 +3,5 @@ DJANGO_SETTINGS_MODULE=settings testpaths=tests addopts=-m "not benchmark" junit_family=legacy +filterwarnings= + ignore::DeprecationWarning:localized_fields.fields.autoslug_field diff --git a/settings.py b/settings.py index b4680b8..42be8fe 100644 --- a/settings.py +++ b/settings.py @@ -1,3 +1,4 @@ +import django import dj_database_url DEBUG = True @@ -51,6 +52,12 @@ 'django.contrib.auth.middleware.AuthenticationMiddleware', ] +# See: https://github.com/psycopg/psycopg2/issues/1293 +if django.VERSION >= (3, 1): + USE_TZ = True + USE_I18N = True + TIME_ZONE = 'UTC' + # set to a lower number than the default, since # we want the tests to be fast, default is 100 LOCALIZED_FIELDS_MAX_RETRIES = 3 diff --git a/setup.py b/setup.py index b076389..51ec29b 100644 --- a/setup.py +++ b/setup.py @@ -98,6 +98,7 @@ def run(self): "autopep8==1.4.4", "isort==4.3.20", "sl-docformatter==1.4", + "click==8.0.2", ], }, cmdclass={