'Performs a SELECT COUNT() and returns the number of records as an
integer.
If the QuerySet is already fully cached this simply returns the length
of the cached results set to avoid multiple SELECT COUNT(*) calls.'

def count(self):

    if (self._result_cache is not None):
        return len(self._result_cache)
    return self.query.get_count(using=self.db)
