#NEWLINE# def get_count_query( self ) : #NEWLINE# #INDENT# '\n        Copies the query object and alters the field list and order by to do a more efficient count\n        ' #NEWLINE# query_copy = self . copy ( ) #NEWLINE# if ( not query_copy . tables ) : #NEWLINE# #INDENT# raise Exception ( 'No tables specified to do a count' ) #NEWLINE# #UNINDENT# for table in query_copy . tables : #NEWLINE# #INDENT# del table . fields [ : ] #NEWLINE# #UNINDENT# query_copy . tables [ 0 ] . add_field ( CountField ( '*' ) ) #NEWLINE# del query_copy . sorters [ : ] #NEWLINE# return query_copy