From c68d60a2de95028fc058fbdecc0e16f65376265c Mon Sep 17 00:00:00 2001 From: arsh Date: Mon, 12 May 2025 12:51:24 -0700 Subject: [PATCH] Allow saving null for decimal pint field --- src/django_pint_field/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/django_pint_field/forms.py b/src/django_pint_field/forms.py index b6efdd0..ded0a2f 100644 --- a/src/django_pint_field/forms.py +++ b/src/django_pint_field/forms.py @@ -304,7 +304,7 @@ def to_python(self, value) -> Optional[Quantity]: if hasattr(quantity, "magnitude") and isinstance(quantity.magnitude, Decimal): validate_decimal_precision(quantity) - else: + elif quantity is not None: try: quantity = self.ureg.Quantity(quantity) except Exception as e: