Monday, January 4, 2021

Re: How can I multiply 2 or more fields in django views or models

Nothing wrong with the query, the problem is that you are trying to multiply two values of a different type.
You can fix that by converting the smallInteger value to decimal.

On Mon, 04 Jan 2021 at 23:01, jose angel encinas ramos <encinasj.angel@gmail.com> wrote:
Hi everyone, i'm a new in django and python and i have a problem

I had a inventory app and I want to multiply 2 fields, coust_buy and quantity, but when execute this query:
views.py
        data = Articles.objects.all().annotate(result=F('coust_buy') * F('quantity'))

the results is this (img down)



what wrong with my query ? b


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f7e5dcbe-f6dd-47a1-8412-42c14aa70e95n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAE0AZGK%3D8wTcc4kwc8tdYnw59HTRS2ncjLq%2BGNcLLEQwuam0wQ%40mail.gmail.com.

No comments:

Post a Comment