[Answer]-How to count objects count that have ForeignKey relationship?

1👍

Exclude blog that has no post, then count.

Blog.objects.exclude(post=None).count()

0👍

You can filter by related model

 Blog.objects.filter(post__isnull=False).count()
👤nes

Leave a comment