[Answer]-Simple reverse in query in django

1👍

Your question is hard to understand, so I’ll look at a couple of interpretations:

  1. You want to get countries for a particular post:

    countries = Country.objects.filter(post=post_instance)
    
  2. You want to get all countries that have any posts:

    countries = Country.objects.filter(post__isnull=False)
    

    Similarly, if you wanted to get countries that don’t have a post associated with them:

    countries = Country.objects.filter(post__isnull=True)
    

Leave a comment