How do I count Django database records?
ExampleCopy code to clipboard
count1 = OrderLines.objects.count() count2 = OrderLines.objects.filter(order_id=4).count() print(count1) print(count2)
A Django count translates to SELECT COUNT(*). If you do not need the records but just the count, this is probably faster then getting all objects and perform a len() with python
Link to documentation or other source
12 Jun 2019
Author: Mies van Hamelen
Would you recommend this example to your colleagues?