Re: multiplying two fields

2021-01-30 Thread Mai Elshiashi
This will work data = Articles.objects.all().annotate(result=ExpressionWrapper(F('cost_buy') * F('quantity') , output_field=FloatField())) now data is a queryset. so you can do something like this data[0].result data.values("result") -- You received this message because you are subscribed to the

Re: multiplying two fields

2021-01-29 Thread Ross Meredith
You need to read the documentation as always - https://docs.djangoproject.com/en/3.1/ref/models/expressions/#using-f-with-annotations It says that the output_field is a keyword argument for the annotate method. On Fri, Jan 29, 2021 at 10:56 PM jose angel encinas ramos < encinasj.an...@gmail.com>

Re: multiplying two fields

2021-01-29 Thread jose angel encinas ramos
tanks Ross, i fixed my error but now only show me this >>> data = Articles.objects.all().annotate(F=('cost_buy') * F('quantity')).output_field=FloatField('result') >>> print(data) >>> what do you think? On Fri, Jan 29, 2021 at 2:54 PM Ross Meredith wrote: > Apologies, typo myself! > > That me

Re: multiplying two fields

2021-01-29 Thread Ross Meredith
Apologies, typo myself! That meant to say "typo" not "type". On Fri, Jan 29, 2021 at 9:52 PM Ross Meredith wrote: > > data = Articles.objects.all().annotate(result=F('coust_buy') * > F('quantity')).output_field=FloatField('result'), > > contains a type for the field "cost_buy" (i.e. not "cou

Re: multiplying two fields

2021-01-29 Thread Ross Meredith
data = Articles.objects.all().annotate(result=F('coust_buy') * F('quantity')).output_field=FloatField('result'), contains a type for the field "cost_buy" (i.e. not "coust_by"). If that isn't it please give us the traceback. On Fri, Jan 29, 2021 at 8:50 PM jose angel encinas ramos < encinasj.an..

multiplying two fields

2021-01-29 Thread jose angel encinas ramos
Guys gd evening I need help,really i don't kwnow how to do a multiply two fields, have a model called Articles. class Articles(models.Model): #models article Nuevo = 'Nuevo' Semi_nuevo = 'Semi_nuevo' Usado = 'Usado' Otros = 'Otros' STATE_ACTUAL = ( (Nuevo, 'Nuevo'), (Semi_nuevo,'Semi_nuevo'), (