Okdoke, well here's an inventive workaround for now, hope this helps
someone else.

calculated_items = Item.objects.filter(cart=self).extra(select=
{'calculated_price': 'SUM(unit_price * quantity)'})[:1]
return calculated_items[0].calculated_price if calculated_items.count
() > 0 else 0

I should probably just use straight SQL for the whole query but the
ORM helps with the join.



On Nov 5, 6:46 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Thu, Nov 5, 2009 at 4:10 PM, davisd <davisd.dav...@gmail.com> wrote:
>
> > Adding an extra field (calculated_price):
>
> > calculated_items = Item.objects.filter(cart=self).extra(select=
> > {'calculated_price': 'unit_price * quantity'})
>
> > works great and the queryset items have the new calculated_price
> > field.
>
> > calculated_items.aggregate(Sum('calculated_price'))
>
> > raises an Exception, telling me:
>
> > Cannot resolve keyword 'calculated_price' into field. Choices are: ...
> > (list of fields on the model)
>
> > It seems to me aggregate should look for available fields in the
> > queryset as opposed to looking on the model.
>
> > Is this a django bug or am I doing something wrong?
>
> > Looks like:
>
> http://code.djangoproject.com/ticket/11671
>
> Karen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to