[Solved]-Django annotate whether exists or not


You can make use of an Exists expression [Django-doc] to determine if there exists a Pet for that Person. For example:

from django.db.models import Exists, OuterRef


Here the model is thus Pet that has a ForeignKey named person to Person. If the fields are named differently, then you should of course update the query accordingly.

Leave a comment