Russell Keith-Magee wrote: > On 10/19/06, zenx <[EMAIL PROTECTED]> wrote: > > > > I want to get the maximum and the minimum values of various numbers. Is > > the following method the best way to do it? > > The most efficient way would be to use SQL; this way, the min and max > would fall out as the result of a single query. > > Unfortunately, this requires some fairly complex use of aggregate > clauses. The only support that Django provides for these clauses is as > part of the extra clause.
I take it 'tag' is a ManyToMany field in 'artista'? Assuming your app is named 'app', you should be able to do something like this: from django.db import connection ... cursor = connection.cursor() cursor.execute(""" select min(c), max(c) from (select tag_id, count(*) as c from app_artista_tags group by tag_id) s""") (min_c, max_c) = cursor.fetchall()[0] cusor.close() I find some things are easier (and faster) to do in SQL so its not necessarilly a bad thing to drop down to custom SQL. -Dave --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---