Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8410683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:14:32+00:00 2026-06-10T00:14:32+00:00

I am trying to get country where some specific post exists, so that I

  • 0

I am trying to get country where some specific post exists, so that I can show only those countries. To do so. I have following code.

Models:

class Country(models.Model):
    name=models.CharField(max_length=100)
    iso_code_2=models.CharField(max_length=4)
    iso_code_3=models.CharField(max_length=4)
    def __unicode__(self):
        return self.name
    def get_countries_with_jobs(self):
        countries=self.objects.filter(id__in=Post.country)
        return countries


class Category(models.Model):
    name=models.CharField(max_length=100)
    title=models.CharField(max_length=100)
    meta_keywords=models.CharField(max_length=100)
    meta_description=models.CharField(max_length=100)
    sort_order=models.IntegerField()
    def __unicode__(self):
        return self.name

class City(models.Model):
    name=models.CharField(max_length=100)
    title=models.CharField(max_length=100)
    meta_keywords=models.CharField(max_length=100)
    meta_description=models.CharField(max_length=100)
    sort_order=models.IntegerField()
    country=models.ForeignKey(Country)
    def __unicode__(self):
        return self.title

class Post(models.Model):
    user=models.ForeignKey(User)
    title=models.CharField(max_length=100)
    publish_date=models.DateField()
    active=models.BooleanField()
    country=models.ForeignKey(Country)
    city=ChainedForeignKey(City,chained_field="country",chained_model_field="country" )
    category=models.ForeignKey(Category)
    description=models.TextField()
    added_by=models.CharField(max_length=70)
    def __unicode__(self):
        return self.title

Here get_countries_with_jobs method have the code that is trying to query and get countries where post exist. Normally one access country of some post, but in this case I need to get countries where post exists. Here it was giving error while calling this method so I tried to write this code in view method as below.

def list(request,template_name='list_posts.html'):
     countries=Country.objects.filter(id__in=Posts.country)
     return render_to_response(template_name,locals(),context_instance=RequestContext(request))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:14:33+00:00Added an answer on June 10, 2026 at 12:14 am

    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)
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get this expression to work, can someone look at it and tell
I am trying to get some data out from a database stored as text
I am trying to get some data from xml file from my C# coding.
For some reason, I can't get the John Resig micro template to work. I've
Im trying to get some values from the below xml feed <?xml version=1.0 ?>
I am trying to provide drop down menus so that users can select their
I am trying to parse some XML in AS3 that I recieve thru a
I am trying to retrieve some specific data, using jQuery to retrieve a JSON
Trying to get a new rails app up and I can't start the server
So i am trying get 2 div-containers which both should contain centered text (Both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.