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)
<django.db.models.fields.FloatField>
>>>

what do you think?

On Fri, Jan 29, 2021 at 2:54 PM Ross Meredith <rossmer...@gmail.com> wrote:

> Apologies, typo myself!
>
> That meant to say "typo" not "type".
>
>
>
> On Fri, Jan 29, 2021 at 9:52 PM Ross Meredith <rossmer...@gmail.com>
> 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 "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...@gmail.com> wrote:
>>
>>> 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'),
>>> (Usado,'Usado'),
>>> (Otros,'Otros')
>>> )
>>> name = models.CharField(max_length=50)
>>> quantity = models.PositiveIntegerField()
>>> fk_brand = models.ForeignKey(Brand, null=True, on_delete=
>>> models.SET_NULL)
>>> model = models.CharField(max_length=50)
>>> fk_category = models.ForeignKey(Category, null=True, 
>>> on_delete=models.SET_NULL)
>>>
>>> cost_buy = models.DecimalField(max_digits=10, decimal_places=2)
>>> fk_supplier = models.ForeignKey(Supplier, null=True, on_delete=
>>> models.SET_NULL)
>>> userful_life = models.DateField()
>>> actual_state = models.CharField(max_length=12, choices=STATE_ACTUAL)
>>> date_check = models.DateField()
>>> location = models.CharField(max_length=50)
>>> img = models.ImageField(upload_to='articles', null=True, blank=True)
>>> description = models.TextField(blank=True)
>>> #actions
>>> created = models.DateTimeField(auto_now_add=True)
>>> update = models.DateTimeField(auto_now=True)
>>>
>>> class Meta:
>>> verbose_name = 'Article'
>>> verbose_name_plural = 'Articles'
>>>
>>> @property
>>> def result(self,*args, **kwargs):
>>> mult = self.cost_buy * self.quantity
>>> return mult
>>>
>>> class Meta:
>>> verbose_name = 'Article'
>>> verbose_name_plural = 'Articles'
>>>
>>> def __str__(self):
>>> return '{} {} {}'.format(self.name ,self.cost_buy, self.quantity)
>>>
>>> so i want to multiply 2 filed , *cost_buy* * *quantity* and the result
>>> show in the template
>>>
>>> i was to try did this query in view.py
>>> data = Articles.objects.all().annotate(result=F('coust_buy') * F(
>>> 'quantity')).output_field=FloatField('result')
>>>
>>>
>>> but isn't work
>>>
>>>
>>>
>>>
>>>
>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/3b573d77-b89a-4b39-95fd-dfd6f9d90910n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/3b573d77-b89a-4b39-95fd-dfd6f9d90910n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAA1Tdz2ka2NskiK5rn8sc8yVQ%3D3xZ8YkTEAUv9HH%2Bb1yiALWqw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAA1Tdz2ka2NskiK5rn8sc8yVQ%3D3xZ8YkTEAUv9HH%2Bb1yiALWqw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
José Ángel Encinas
Ing. Tecnologias de la información


Cel:  6622267620  <6622267620>

   *                   Never give up...*
<http://mx.linkedin.com/in/jencinas>   I
<http://twitter.com/encinasjangel>  I   [image:
https://us04web.zoom.us/j/4514417813] <https://us04web.zoom.us/j/4514417813>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF3iVr_MJi%3DkrPxjD%3DeD%2B0s9zf0-NFVs%3Dmb5jAMhjjmSsk8rZg%40mail.gmail.com.

Reply via email to