mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Tweak validation for custom date fields
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from datetime import datetime
|
from datetime import datetime, date
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
@ -317,10 +317,11 @@ class CustomField(models.Model):
|
|||||||
|
|
||||||
# Validate date
|
# Validate date
|
||||||
if self.type == CustomFieldTypeChoices.TYPE_DATE:
|
if self.type == CustomFieldTypeChoices.TYPE_DATE:
|
||||||
try:
|
if type(value) is not date:
|
||||||
datetime.strptime(value, '%Y-%m-%d')
|
try:
|
||||||
except ValueError:
|
datetime.strptime(value, '%Y-%m-%d')
|
||||||
raise ValidationError("Date values must be in the format YYYY-MM-DD.")
|
except ValueError:
|
||||||
|
raise ValidationError("Date values must be in the format YYYY-MM-DD.")
|
||||||
|
|
||||||
# Validate selected choice
|
# Validate selected choice
|
||||||
if self.type == CustomFieldTypeChoices.TYPE_SELECT:
|
if self.type == CustomFieldTypeChoices.TYPE_SELECT:
|
||||||
|
Reference in New Issue
Block a user