Copies the query object and alters the field list and order by to do a more efficient count

def get_count_query(self):
        """
        Copies the query object and alters the field list and order by to do a more efficient count
        """
        query_copy = self.copy()
        if not query_copy.tables:
            raise Exception('No tables specified to do a count')

        for table in query_copy.tables:
            del table.fields[:]

        query_copy.tables[0].add_field(CountField('*'))
        del query_copy.sorters[:]
        return query_copy