Skip to content

Commit

Permalink
Don't require null=True for the CharFields #49
Browse files Browse the repository at this point in the history
  • Loading branch information
aweakley committed May 14, 2024
1 parent 61c792e commit 17f7960
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions edtf/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions edtf_django_tests/edtf_integration/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
),
),
Expand All @@ -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)",
),
),
Expand Down
4 changes: 2 additions & 2 deletions edtf_django_tests/edtf_integration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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').",
)
Expand All @@ -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~').",
)

Expand Down

0 comments on commit 17f7960

Please sign in to comment.