Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't have an empty field #7

Open
Josh-Woodcock opened this issue Oct 5, 2021 · 4 comments
Open

can't have an empty field #7

Josh-Woodcock opened this issue Oct 5, 2021 · 4 comments

Comments

@Josh-Woodcock
Copy link

I am working on a project that has start and end date fields. Ideally the end date field would be optional.

However PartialDate won't accept an empty string, or None despite what it says in the documentation; or null=True.

These are the kind of errors I have received -

["'' is not a valid date string (YYYY, YYYY-MM, YYYY-MM-DD)"]

image

@lorinkoz
Copy link
Collaborator

lorinkoz commented Oct 5, 2021

Empty string should not be valid.

For empty dates None should be used. Is the partial date field null=True?

@Josh-Woodcock
Copy link
Author

Tried again but still get an error, reproduced below with identifiying information taken out. It appears the error lies in the pareDate function when it receives a blank field.

  ValidationError at /admin/pages/23/edit/
  ["'' is not a valid date string (YYYY, YYYY-MM, YYYY-MM-DD)"]
  Request Method: GET
  Request URL:    http://localhost:8000/admin/pages/23/edit/?next=/admin/dialectics/journal/
  Django Version: 3.1.7
  Exception Type: ValidationError
  Exception Value:    
  ["'' is not a valid date string (YYYY, YYYY-MM, YYYY-MM-DD)"]
  Exception Location: /wagtail-env/lib/python3.8/site-packages/partial_date/fields.py, line 105, in parseDate
  Python Executable:  /wagtail-env/bin/python
  Python Version: 3.8.10

The field is written as ->

  active_end = PartialDateField(
          blank=True,
          null=True,
      )

If it makes any difference we are using Wagtail not pure Django.

@lorinkoz
Copy link
Collaborator

lorinkoz commented Oct 5, 2021

Please make sure that your forms or any other interface to the useris properly converting the "empty user input" to None instead of "".

@xjlin0
Copy link

xjlin0 commented Feb 26, 2022

I encounter the same thing and this is default Django admin page, I have to add blank=True to make the admin page saving work, and convert empty string to None in model's save() method. It maybe more convenient if django_partial_date can ignore the empty string.

https://stackoverflow.com/a/6993885/4257237

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants