1👍
Override the __init__
method of your model field and set the max_digits
based on the related unit of measure.
class ProductForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(ProductForm, self).__init__(*args, **kwargs)
self.fields['qty_available'] = models.DecimalField(max_digits=10, decimal_places=self.instance.uom.precision)
class Meta:
model = Product
0👍
If it’s just a presentation problem, you can use a simple_tag
in your templates:
@register.simple_tag
def format_qty_available(product):
return product.qty_available.quantize(Decimal(10) ** -product.uom.precision)
- [Answer]-How to replace certain values in a queryset with Django?
- [Answer]-Django tag for relative urls
- [Answer]-No csrf token after ajax page load
- [Answer]-Save data in Models where field name comes from a variable
- [Answer]-Make a query that hits the DB and then make others from it without hitting
Source:stackexchange.com