Django 1.11.2
I'd like to use SelectDateWidget.
class FrameDate(models.Model):
through_date = models.DateField(null=True,
blank=True,
verbose_name=_("through"))
...
class FrameDateForm(ModelForm):
def clean_through_date(self):
pass # Breakpoint
class Meta:
model = FrameDate
exclude = []
years = range(1800, datetime.datetime.now().year + 1)
widgets = {
'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.
On Monday 12 June 2017 03:28:29 Nonverbis M wrote:
> 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.
Do you have a backtrace?
--
Melvyn Sopacua