On 23 jan, 17:27, Trevor Stanley <h...@balancingact.me.uk> wrote: > Karen > > Thanks for your reply. The reason I was trying to filter the id with > count was that I had read somewhere that you have to pass sum at least > two arguments (but may be I mis-understood what I was reading!)
The Python builtin sum() function takes an iterable and an optional initial value (which defaults to int '0'). > I have changed my code to: > > def get_fringe_value(self): > ft = >Fringe.objects.select_related().filter(id__in=self.fringe.all()).values() This is a very complicated and innefficient way to write: ft = self.fringe.select_related().values() Also and FWIW, I don't see the need for a select_related here, so you could as well make it: ft = self.fringe.values() But since you only want to sum the percentages, what you want is really: ft = self.fringe.values_list('percentage', flat=True) and then apply sum() to this list. But why use the builtin sum() when the database already knows how to do a sum ? > qft=ft(sum('percentage')) Err... you're trying to sum the chars in the 'percentage' string with an initial value of int zero - ie, "sum('percentage')" is another way to spell: initial = 0 for char in "percentage": initial += char Which obviously leads to the TypeError since you cannot add integers and strings. Also, I just don't get what result you'd expect from passing the result of the call to 'some' to a call to ft. To make a long story short: you don't know what you're doing and try just anything that comes to your mind. This is called "programming by accident", and is the best way to never learn to program. -- 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.