user2492364
user2492364

Reputation: 6713

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

Upvotes: 10

Views: 10009

Answers (1)

Burhan Khalid
Burhan Khalid

Reputation: 174748

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.

Upvotes: 8

Related Questions