I have a model field full_time_equivalent
:
full_time_equivalent = models.DecimalField(
max_digits=5,
decimal_places=2,
default=100,
validators=[
MinValueValidator(Decimal(0)),
MaxValueValidator(Decimal(100))
]
)
To ensure that the validators fire I have override save
with:
def save(self, *args, **kwargs):
# Run validations
self.full_clean()
return super().save(*args, **kwargs)
With the following test:
project2_membership = ProjectMembership(
user=self.new_user,
project=project2,
is_project_manager=False,
full_time_equivalent=10.01
)
When I step into the validation the following value is shown and respective error:
Decimal('10.0099999999999997868371792719699442386627197265625')
django.core.exceptions.ValidationError:
{'full_time_equivalent': ['Ensure that there are no more than 5 digits in total.']
What am I doing wrong?