diff --git a/edtf/fields.py b/edtf/fields.py index b38873b..525fef6 100644 --- a/edtf/fields.py +++ b/edtf/fields.py @@ -125,8 +125,8 @@ def update_values(self, instance, *args, **kwargs): # Get existing value to determine if update is needed existing_value = getattr(instance, self.attname, None) - direct_input = getattr(instance, self.direct_input_field, None) - natural_text = getattr(instance, self.natural_text_field, None) + direct_input = getattr(instance, self.direct_input_field, "") + natural_text = getattr(instance, self.natural_text_field, "") # if direct_input is provided and is different from the existing value, update the EDTF field if direct_input and ( @@ -138,7 +138,7 @@ def update_values(self, instance, *args, **kwargs): # TODO pyparsing.ParseExceptions are very noisy and dumps the whole grammar (see https://github.com/ixc/python-edtf/issues/46) # set the natural_text (display) field to the direct_input if it is not provided - if natural_text is None: + if natural_text == "": setattr(instance, self.natural_text_field, direct_input) elif natural_text: diff --git a/edtf_django_tests/edtf_integration/migrations/0001_initial.py b/edtf_django_tests/edtf_integration/migrations/0001_initial.py index 286a9de..0311290 100644 --- a/edtf_django_tests/edtf_integration/migrations/0001_initial.py +++ b/edtf_django_tests/edtf_integration/migrations/0001_initial.py @@ -28,7 +28,7 @@ class Migration(migrations.Migration): blank=True, help_text="Enter the date in natural language format (e.g., 'Approximately June 2004').", max_length=255, - null=True, + null=False, verbose_name="Date of creation (display)", ), ), @@ -38,7 +38,7 @@ class Migration(migrations.Migration): blank=True, help_text="Enter the date in EDTF format (e.g., '2004-06~').", max_length=255, - null=True, + null=False, verbose_name="Date of creation (EDTF format)", ), ), diff --git a/edtf_django_tests/edtf_integration/models.py b/edtf_django_tests/edtf_integration/models.py index f5dbcc0..5120889 100644 --- a/edtf_django_tests/edtf_integration/models.py +++ b/edtf_django_tests/edtf_integration/models.py @@ -7,7 +7,7 @@ class TestEvent(models.Model): date_display = models.CharField( "Date of creation (display)", blank=True, - null=True, + null=False, max_length=255, help_text="Enter the date in natural language format (e.g., 'Approximately June 2004').", ) @@ -16,7 +16,7 @@ class TestEvent(models.Model): "Date of creation (EDTF format)", max_length=255, blank=True, - null=True, + null=False, help_text="Enter the date in EDTF format (e.g., '2004-06~').", )