Thanks Tom, worked like a charm. So actually qs is a collection of results and I can iterate through them. Good to know.
Cheers. On Dec 7, 7:52 pm, Tom Evans <tevans...@googlemail.com> wrote: > On Tue, Dec 7, 2010 at 5:29 PM, mongoose <darrenma1...@gmail.com> wrote: > > Hi all, > > > I have this in my model.py > > def recipe_cost(self): > > > total = IngredientInfo.objects.filter(recipe = > > self.id).aggregate(Sum('total')).values() > > > return total > > > Then in my admin.py I call that to display the cost. > > class RecipeAdmin(admin.ModelAdmin): > > list_display = ('title','recipe_cost') > > > I can see the cost but it's being returned like this: > > [Decimal('500.00')] > > > But obviously I'd just want the value 500. What should I change? > > > Thanks > > What you are calling total isn't the total, its a ValuesQuerySet. You > want to extract the value from there, and convert it into whatever > format you want. > > Eg: > > def recipe_cost(self): > qs = IngredientInfo.objects.filter( > recipe=self.id).aggregate(Sum('total')).values() > return unicode(qs[0]) > > Cheers > > Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.