Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Provide step attribute with WeightField

Marcin Gębala694a803434ef
diff --git a/saleor/product/forms.py b/saleor/product/forms.py
index f6aaa86f54..abddca430d 100644
--- a/saleor/product/forms.py
+++ b/saleor/product/forms.py
@@ -85,9 +85,11 @@ class WeightInput(forms.TextInput):
class WeightField(forms.DecimalField):
-
- def __init__(self, unit, widget=WeightInput, *args, **kwargs):
+ def __init__(self, unit, decimal_places, widget=WeightInput, *args,
+ **kwargs):
self.unit = unit
+ step = 10 ** -decimal_places
if isinstance(widget, type):
- widget = widget(unit=self.unit, attrs={'type': 'number'})
+ widget = widget(unit=self.unit,
+ attrs={'type': 'number', 'step': step})
super(WeightField, self).__init__(*args, widget=widget, **kwargs)
diff --git a/saleor/product/models/fields.py b/saleor/product/models/fields.py
index 35eaefed28..fb3960b33a 100644
--- a/saleor/product/models/fields.py
+++ b/saleor/product/models/fields.py
@@ -18,6 +18,7 @@ class WeightField(models.DecimalField):
def formfield(self, **kwargs):
defaults = {'unit': self.unit,
+ 'decimal_places': self.decimal_places,
'form_class': forms.WeightField}
defaults.update(kwargs)
return super(WeightField, self).formfield(**defaults)