title: How to get foreign key relation array in django
body: <p>I have country table and its translation table with foreign key <code>country_id</code>, and city table with foreign key <code>country_id</code>, and city translation table with foreign key <code>city_id</code>.
  So my model.py like this.</p>
  
  <pre><code>from django.db import models
  
  # Create your models here.
  
  
  class Country(models.Model):
      #id             = models.IntegerField(primary_key=True)
      iso_code    = models.CharField(max_length=2, unique=True)
      slug        = models.CharField(max_length=255, unique=True)
      is_featured = models.IntegerField(max_length=1)
  
      class Meta:
          db_table = 'rh_countries'
  
  class CountryTranslation(models.Model):
      country     = models.ForeignKey(Country, on_delete=models.CASCADE)
      name        = models.CharField(max_length=255)
      description = models.TextField(blank=True, null=True)
      locale      = models.CharField(max_length=2)
  
      class Meta:
          db_table = 'rh_countries_translations'
  
  class City(models.Model):
      country     = models.ForeignKey(Country, on_delete=models.CASCADE)
  
      class Meta:
          db_table = 'rh_cities'
  
  class CityTranslation(models.Model):
      city        = models.ForeignKey(City, on_delete=models.CASCADE)
      name        = models.CharField(max_length=255)
      description = models.TextField(blank=True, null=True)
      locale      = models.CharField(max_length=2)
  
      class Meta:
          db_table = 'rh_city_translations'
  </code></pre>
  
  <p>And my views.py file like this.</p>
  
  <pre><code>from django.shortcuts import render
  
  # Create your views here.
  from django.http import HttpResponse
  from django.template import loader
  from home.models import Country, CountryTranslation, City, CityTranslation
  from django.db.models import F, Count
  
  def index(request):
      #return HttpResponse("Hello, world. You're at the polls index.")
      template = loader.get_template('home/index.html')
      context = {
          "countries" : Country.objects.filter(
                              is_featured=1,
                              countrytranslation__locale='en'
                          ).annotate(
                              name=F('countrytranslation__name'),
                              totalCities=Count('city', distinct=True)
                          )
      }
      return render(request, 'home/index.html', context)
  </code></pre>
  
  <p>This way I have got total cities of the country. But I want list of 3 cities name of all country with locale <code>en</code>.
  Please help me to retrieve data such way. 
  sample output should be: </p>
  
  <pre><code>Array{
      0 =&gt; {
          id =&gt; 1
          name =&gt; 'Australia',
          is_featured =&gt; 1,
          totalCities =&gt; 5,
          cities =&gt; {
              0 =&gt; {
                  id =&gt; 1,
                  name =&gt; 'Sydney',
                  locale =&gt; 'en'
              },
              1 =&gt; {
                  id =&gt; 2,
                  name =&gt; 'Melbourne',
                  locale =&gt; 'en'
              },
              2 =&gt; {
                  id =&gt; 3,
                  name =&gt; 'Perth',
                  locale =&gt; 'en'
              }
          }
      },
      2 =&gt; {
          id =&gt; 2
          name =&gt; 'Spain',
          is_featured =&gt; 1,
          totalCities =&gt; 12,
          cities =&gt; {
              0 =&gt; {
                  id =&gt; 9,
                  name =&gt; 'Madrid',
                  locale =&gt; 'en'
              },
              1 =&gt; {
                  id =&gt; 10,
                  name =&gt; 'Bercelona',
                  locale =&gt; 'en'
              },
              2 =&gt; {
                  id =&gt; 11,
                  name =&gt; 'Valencia',
                  locale =&gt; 'en'
              }
          }
      }
  }
  </code></pre>