From e6e012b86b2a747fb86764fb04c1c0269d7f0fe4 Mon Sep 17 00:00:00 2001 From: marcin-koziol-iteo Date: Thu, 7 Mar 2024 13:48:25 +0100 Subject: [PATCH] Another fix for generating decimal examples --- audoma/examples.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/audoma/examples.py b/audoma/examples.py index c22585c..656fb74 100644 --- a/audoma/examples.py +++ b/audoma/examples.py @@ -49,8 +49,13 @@ def generate_value(self) -> float: Random value between min_value and max_value """ min_val = float(getattr(self.field, "min_value", 1) or 1) - max_val = float(getattr(self.field, "max_value", 1000) or 1000) - decimal_places = getattr(self.field, "decimal_places", None) + decimal_places = getattr(self.field, "decimal_places", 0) or 0 + max_digits = getattr(self.field, "max_digits", 4) or 4 + max_val_fallback = 10 * (max_digits - decimal_places) - 1 + max_val = float( + getattr(self.field, "max_value", max_val_fallback) or max_val_fallback + ) + if decimal_places: fmt = f".{decimal_places}f" return Decimal(f"{(max_val):{fmt}}")