I have the following model:
class MeasurementParameter(models.Model):
tolerance = models.FloatField()
set_value = models.FloatField()
tol_low = None
tol_high = None
def tolerance_band(self):
tol = self.set_value * self.tolerance/100
self.tol_high = self.set_value + tol
self.tol_low = self.set_value - tol
print self.tol_low
return self.tol_high, self.tol_low
I wish to set the calculated local variables tol_low and tol_high using the tolerance_band method.
The model is has a ManyToMany relationship with another model called Product.
class Product(models.Model):
name = models.CharField(max_length=100)
description = models.CharField(max_length=1000)
parameters = models.ManyToManyField(MeasurementParameter, related_name='measurement')
def calc_all_tol_bands(self):
for parameter in self.parameters.all():
hi, lo = parameter.tolerance_band()
def __str__(self):
return self.name
So in my view I attempt to calculate all tolerance bands by:
product.calc_all_tol_bands()
However if I try and get the local variables:
product.parameters.all()[0].tol_low
I get None all the time.
What do I need to do to be able to set calculated values in the MeasurementParameter model?
John.