On Tue, Aug 24, 2010 at 2:29 PM, wally <geoff.he...@gmail.com> wrote: > I'm getting some strange errors when trying to use the aggregate > functions. My model looks like... > > class test(models.Model): > a = models.IntegerField() > > After creating a few records, I try the following: > >>>> test.objects.all().aggregate(sum('a')) > Traceback (most recent call last): > File "<console>", line 1, in ? > TypeError: unsupported operand type(s) for +: 'int' and 'str' > >>>> test.objects.all().aggregate(max('a')) > Traceback (most recent call last): > File "<console>", line 1, in ? > File "/usr/lib/python2.4/site-packages/django/db/models/query.py", > line 303, in aggregate > kwargs[arg.default_alias] = arg > AttributeError: 'str' object has no attribute 'default_alias' > > I get the same response from django 1.2.0 and current SVN, .python > 2.4.3 under CentOS 5.4. > > Am I missing something here? Do I have the syntax correct? Any help > would be appreciated.
Almost, but not quite. There is a difference between max() the python builtin function for finding a maximum value, and Max(), Django's representation of an aggregate function. In both your examples, you're using the Python builtin. Max, Sum, and the rest of Django's aggregates all need to be imported from django.db.models. Yours, Russ Magee %-) -- 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.