Friday, June 30, 2017

Re: SelectDateWidget when DateField is not required

I can't reproduce a crash. If I select only a month, I see a validation error, "Enter a valid date."

On Monday, June 12, 2017 at 6:28:29 AM UTC-4, Nonverbis M wrote:

Django 1.11.2

I'd like to use SelectDateWidget.

class FrameDate(models.Model):
= models.DateField(null=True,

class FrameDateForm(ModelForm):

def clean_through_date(self):
pass # Breakpoint

class Meta:
= FrameDate
= []

= range(1800, + 1)

= {
'frame': forms.HiddenInput(),
'from_date': forms.SelectDateWidget(years=years),
'through_date': forms.SelectDateWidget(years=years)

As we can see, this DateField is not required. And have an empty choice at the top of the list ("---").

The problem is that when a user inputs only a month we'll get ValueError springing out to the user in case of Debug=True.

There is that method clean_through_date and the break point in it. But in case of incomplete set of month, day and year the program will not even call this clean_through_date() method. This method is called in two cases:

1) if the through_date is completely empty.

2) if it is completely filled.

If it is partially filled, form validation is ignored completely. The program explodes at CreateView.

Could you comment on it? And give me a kick here: how to warn the user that s/he must either fill month, day and year or don't touch the through_date at all.

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment