[Answer]-Why does values query set not match model attributes

1👍

The value in the database is is what you see with .values('ratio')
If you want the value to be x.ratio = x.ratio * self.qty, you’ll have to save that model instance into the database after it has been initialiazed with your Python code with the calculation

A better approach would be to use a different field, one for ratio, and one for the calculated values you need (and decide if you want to save them into the DB or calculate on the fly, unless required, it’s usually better not to store any calculated fields, that way your data cannot be inconsistent in the DB)

👤bakkal

Leave a comment