【发布时间】:2020-11-18 10:36:48
【问题描述】:
我正在尝试验证我的 Django 表单中的出生日期字段。我希望 d_o_b 字段小于当前年份。
def validate_dob(value):
# fxn that check if date of birth is not the current year
if value > datetime.date.year():
raise forms.ValidationError('Date must be greater than current year')
尝试执行上述代码时出现以下错误:
TypeError at /account/edit/ 'getset_descriptor' object is not callable
这是我的表格:
class ProfileEditForm(forms.ModelForm):
dob = forms.DateField(validators = [validate_dob])
class Meta:
model = Profile
fields = ('dob', 'photo')
labels = {
'dob': ('Date of birth'),
}
widgets = {
'dob': DateInput(attrs={'type': 'date'})
}
【问题讨论】: