What am I doing wrong?
JavaScript
x
4
1
class MyModel(models.Model):
2
name = models.CharField(max_length=100, verbose_name=_("Name"), blank=False, null=False)
3
rating = models.DecimalField(max_digits=2, decimal_places=2, default=0)
4
I do something like that:
JavaScript
1
4
1
average = count/len(votes)
2
mymodel.rating = average
3
mymodel.save()
4
count
is the sum of all ratings of given MyModel
and votes is an array of those ratings, their division gives an average rating for MyModel (sorry if I described it incorrectly due to my poor English).
If i change previous to:
JavaScript
1
3
1
mymodel.name = 'anything'
2
mymodel.save()
3
Then ‘anything’ ends up in the database, but rating does not.
Why? am I using wrong field type?
Alan.
Advertisement
Answer
max_digits is a number of digits before and after the decimal point. With your settings it allows you to store numbers between 0.00 and 0.99. Is it right? I can not figure out the range of values for average variable.