'unicode' object has no attribute 'lookup'

1

I'm trying to add a set of values belonging to id_jovenclub

def detalle_jc(request, id_jovenclub ):
    jc = jovenclub.objects.get(pk=id_jovenclub)
    datos=ingresos.objects.all()
    print jc.ingresos_set.all()
    **ing = ingresos.objects.aggregate(pk=id_jovenclub)**
    natural=ing.natural
    sum=0
    for ingreso in jc.ingresos_set.all():
        sum=ingreso.get_importe()

    sum=(round((sum/jc.plan_gral)*100,2))

When I execute the code it gives me the following error:

  

'unicode' object has no attribute 'lookup'

I think it should be because aggregate does not work with pk queries, but try with ing = ingresos.objects.annotate and it does not work either.

    
asked by Roly Miranda Díaz 21.04.2017 в 17:41
source

1 answer

1

The domain aggregation functions, called Aggregate in Django, perform mathematical operations in a specific field of a table. These operations can be 1 : count, average, sum, maximum, minimum ... but beware: mathematical operations on a field.

In your view you use the aggregate method on id , which is generally an incremental numeric field, but you do not indicate the operation to be performed .

Ideally, you would use a field with more information than id so that the result adds value or allows you to make better decisions.

This is an example of the options you can perform.

Average of the dates

from django.db.models import Avg
jovenclub.objects.all().aggregate(Avg('ingresos'))

Maximum income

from django.db.models import Max
jovenclub.objects.all().aggregate(Max('ingresos'))

You can view the full Aggregate documentation at this link .

1 : Without this being an exhaustive list.

    
answered by 21.04.2017 в 18:06