Django: value has an invalid date format. It must be in the format YYYY-MM-DD

I have a question
I use xpath to get item['releaseday'] from the site.
When xpath didn't get the value

This will throw an error:

 django.core.exceptions.ValidationError: [u"'' value has an invalid date format. It must be in YYYY-MM-DD format."] 

in my models.py I set null = True and blank = True it seems that does not work

 releaseday = models.DateField(null=True,blank=True) 

I am trying to add this code but not work

  if 'releaseday' not in item: item['releaseday']='' 

How can i edit ??? Please help me, thanks.

+5
source share
1 answer

Use item.get('releaseday') or None .

You will solve two problems:

  • When the key does not exist, the default will be None , which is valid for your model, since you have null=True .

  • If the key exists but is empty, then it will result in None , which is a valid value for your model.

+5
source

Source: https://habr.com/ru/post/1210089/


All Articles