[Fixed]-Looping Django queryset with multiple values in a column

1👍

MyDataModel.foo is a models.CharField, while you’re trying to get a Decimal from it. The types don’t match. Try models.DecimalField for foo:

class MyDataModel(models.Model):
    id_in_database = models.IntegerField(primary_key=True, blank=False, null=False)
    foo = models.DecimalField(max_digits=5, decimal_places=2)

You will need to run

manage.py makemigrations
manage.py migrate

Which might be a bit problematic if you already have data in the tables. Which makes me wonder if you have put the value ‘55,22’ manually in that sql tables…

👤cybfox

Leave a comment