Course.objects.all().annotate(total=Count('recipe', distinct=True)).filter(total=0).delete()