[Fixed]-In Django how can I get a queryset of all the records that have a particular reverse relationship?


You can use __isnull to filter all outcomes that have a related Programme.

outcomes = Outcome.objects.filter(outcome_programme__isnull=False)

If more than one programme can have the same outcome, you might need to use distinct() to prevent duplicates.

outcomes = Outcome.objects.filter(programme__isnull=False).distinct()

Leave a comment