Re: [Django] #11765: models.DateField(null=True, blank=True) accepts None, but not the empty string ''

9 views
Skip to first unread message

Django

unread,
Apr 11, 2013, 8:29:47 AM4/11/13
to django-...@googlegroups.com
#11765: models.DateField(null=True, blank=True) accepts None, but not the empty
string ''
-------------------------------------+-------------------------------------
Reporter: shmengie | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: master
(models, ORM) | Resolution: invalid
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Brendan):

* ui_ux: => 0
* type: => Uncategorized
* severity: => Normal
* easy: => 0


Comment:

I agree, I just fixed my problem by adding
{{{#!python
def clean(self):
cleaned_data = super(MyForm, self).clean()
if not cleaned_data['my_date']:
cleaned_data['my_date'] = None
return cleaned_data
}}}

to my form. Without this I received the error
{{{#!python
ValidationError: [u"'' value has an invalid date format. It must be in
YYYY-MM-DD format."]
}}}

even though I had blank=True, null=True set in my model and required=False
set in my form.

--
Ticket URL: <https://code.djangoproject.com/ticket/11765#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 7, 2013, 3:51:13 PM8/7/13
to django-...@googlegroups.com
#11765: models.DateField(null=True, blank=True) accepts None, but not the empty
string ''
-------------------------------------+-------------------------------------
Reporter: shmengie | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: master
(models, ORM) | Resolution: invalid
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by yekibud):

I got this error using crispy-forms and not specifying my Date field in
Meta.fields. Adding a clean()n method didn't help but adding the Date
field back to Meta.fields did.

--
Ticket URL: <https://code.djangoproject.com/ticket/11765#comment:8>

Django

unread,
Nov 16, 2021, 6:46:27 PM11/16/21
to django-...@googlegroups.com
#11765: models.DateField(null=True, blank=True) accepts None, but not the empty
string ''
-------------------------------------+-------------------------------------
Reporter: shmengie | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:

| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by htelsiz):

same thing happened to me

--
Ticket URL: <https://code.djangoproject.com/ticket/11765#comment:9>

Reply all
Reply to author
Forward
0 new messages