Count number of foreign keys in Django <p>I've read the documentation and all the other answers on here but I can't seem to get my head around it. </p> <p><strong>I need to count the number of foreign keys in an other table connected by a foreign key to a row from a queryset.</strong></p> <pre><code>class PartReference(models.Model): name = models.CharField(max_length=10) code = models.IntegerField() class Part(models.Model): code = models.ForeignKey(PartReference) serial_number = models.IntegerField() </code></pre> <p>I'll do something like:</p> <pre><code>results = PartReference.objects.all() </code></pre> <p>But I want a variable containing the count of the number of parts like any other field, something like:</p> <pre><code>results[0].count </code></pre> <p>to ultimately do something like:</p> <pre><code>print(results[0].name, results[0].code, results[0].count) </code></pre> <p>I can't wrap my head around the <a href="https://docs.djangoproject.com/en/1.9/ref/models/relations/" rel="nofollow">Django documentation</a>- There is a some stuff going on with <code>entry_set</code> in the example, but doesn't explain where <code>entry</code> came from or how it was defined.</p>