Ticket #2479: aggregate.diff

File aggregate.diff, 984 bytes (added by dev@…, 18 years ago)

quick'n'dirty aggregate function

  • db/models/query.py

     
    301301        self._result_cache = None
    302302    delete.alters_data = True
    303303
     304    def aggregrate(self, function, field):
     305        """Performs a simple aggregate function on field"""
     306        counter = self._clone()
     307        counter._order_by = ()
     308        counter._offset = None
     309        counter._limit = None
     310        counter._select_related = False
     311        select, sql, params = counter._get_sql_clause()
     312        cursor = connection.cursor()
     313        # absolutely no input checking
     314        cursor.execute( "SELECT %s(%s)" % (function, backend.quote_name(field)) + sql, params)
     315        return cursor.fetchone()[0]       
     316
     317
    304318    ##################################################
    305319    # PUBLIC METHODS THAT RETURN A QUERYSET SUBCLASS #
    306320    ##################################################
Back to Top