title: How to make an Inner Join in django?
body: <p>I want to show in an Html the name of the city, state, and country of a publication. But they are in different tables.</p>
  
  <p>Here is my <strong>models.py</strong></p>
  
  <pre><code>class country(models.Model):
      country_name = models.CharField(max_length=200, null=True)
      country_subdomain = models.CharField(max_length=3, null=True)
      def __str__(self):
          return self.country_name
  
  class countrystate(models.Model):
      state_name = models.CharField(max_length=200, null=True)
      country = models.ForeignKey(country, on_delete=models.CASCADE, null=True)
      importance = models.IntegerField(null=True)
      def __str__(self):
          return self.state_name
  
  class city(models.Model):
      city_name = models.CharField(max_length=200, null=True)
      countrystate = models.ForeignKey(countrystate, on_delete=models.CASCADE, null=True)
      def __str__(self):
          return self.city_name
  
  class publication(models.Model):
      user = ForeignKey(users, on_delete=models.CASCADE, null=False)
      title= models.CharField(max_length=300, null=True)
      country=models.ForeignKey(country, on_delete=models.CASCADE, null=True)
      countrystate=models.ForeignKey(countrystate, on_delete=models.CASCADE, null=True)
      city=models.ForeignKey(city, on_delete=models.CASCADE, null=True)
  
      def __str__(self):
          return self.title
  </code></pre>
  
  <p>Here is my views.py</p>
  
  <pre><code>def publications(request):
      mypublications = publication.objects.filter(user_id=request.session['account_id'])
      dic.update({"plist": mypublications })
      return render(request, 'blog/mypublications.html', dic)
  </code></pre>
  
  <p>In a django view, what is the equivalent of the next sql query?</p>
  
  <pre><code>SELECT p.user_id, p.title, c.cuntry_id, c.country_name, s.state_id, s.state_name, y.city_id, y.city_name FROM publication AS p
  INNER JOIN country AS c ON c.id = p.country_id
  INNER JOIN countrystate AS s ON s.id = p.countrystate_id
  INNER JOIN city AS y ON y.id = p.city_id
  </code></pre>