Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

It will cause 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 seems like not work

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

I try add this code,but not work

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

How can I edit???
Please guide me thank you

like image 747
user2492364 Avatar asked Dec 30 '14 07:12

user2492364


1 Answers

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

You'll solve two problems:

  1. When the key does not exist, this will default to None, which is valid input for your model as you have null=True.

  2. If the key exists but its blank '', then it will result in None which is a valid value for your model.

like image 185
Burhan Khalid Avatar answered Sep 17 '22 10:09

Burhan Khalid