mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 08:25:17 -06:00
Apply suggested changes from PR
This commit is contained in:
parent
1f0daa24f7
commit
1e5b20970a
@ -322,6 +322,8 @@ class CustomField(CloningMixin, ExportTemplatesMixin, WebhooksMixin, ChangeLogge
|
||||
initial=initial,
|
||||
max_digits=12,
|
||||
decimal_places=4,
|
||||
min_value=self.validation_minimum,
|
||||
max_value=self.validation_maximum
|
||||
)
|
||||
|
||||
# Boolean
|
||||
@ -496,13 +498,11 @@ class CustomField(CloningMixin, ExportTemplatesMixin, WebhooksMixin, ChangeLogge
|
||||
|
||||
# Validate decimal
|
||||
elif self.type == CustomFieldTypeChoices.TYPE_DECIMAL:
|
||||
if type(value) is not decimal.Decimal and type(value) is not str:
|
||||
if type(value) is not decimal.Decimal:
|
||||
raise ValidationError("Value must be a decimal.")
|
||||
|
||||
converted = decimal.Decimal(value)
|
||||
if self.validation_minimum is not None and converted < self.validation_minimum:
|
||||
if self.validation_minimum is not None and value < self.validation_minimum:
|
||||
raise ValidationError(f"Value must be at least {self.validation_minimum}")
|
||||
if self.validation_maximum is not None and converted > self.validation_maximum:
|
||||
if self.validation_maximum is not None and value > self.validation_maximum:
|
||||
raise ValidationError(f"Value must not exceed {self.validation_maximum}")
|
||||
|
||||
# Validate boolean
|
||||
|
@ -3,8 +3,6 @@ from django import forms
|
||||
from django.conf import settings
|
||||
from django_filters.constants import EMPTY_VALUES
|
||||
|
||||
from utilities.forms import MACAddressField
|
||||
|
||||
|
||||
def multivalue_field_factory(field_class):
|
||||
"""
|
||||
@ -23,14 +21,6 @@ def multivalue_field_factory(field_class):
|
||||
field.to_python(v) for v in value if v
|
||||
]
|
||||
|
||||
def run_validators(self, value):
|
||||
for v in value:
|
||||
super().run_validators(v)
|
||||
|
||||
def validate(self, value):
|
||||
for v in value:
|
||||
super().validate(v)
|
||||
|
||||
return type(f'MultiValue{field_class.__name__}', (NewField,), dict())
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user