MCPcopy
hub / github.com/django/django / count

Method count

django/db/models/query.py:643–654  ·  view source on GitHub ↗

Perform a SELECT COUNT() and return the number of records as an integer. If the QuerySet is already fully cached, return the length of the cached results set to avoid multiple SELECT COUNT(*) calls.

(self)

Source from the content-addressed store, hash-verified

641 return await sync_to_async(self.aggregate)(*args, **kwargs)
642
643 def count(self):
644 """
645 Perform a SELECT COUNT() and return the number of records as an
646 integer.
647
648 If the QuerySet is already fully cached, return the length of the
649 cached results set to avoid multiple SELECT COUNT(*) calls.
650 """
651 if self._result_cache is not None:
652 return len(self._result_cache)
653
654 return self.query.get_count(using=self.db)
655
656 async def acount(self):
657 return await sync_to_async(self.count)()

Callers 1

as_sqlMethod · 0.45

Calls 1

get_countMethod · 0.80

Tested by

no test coverage detected