title: Django Rest Framework - mapping serializers fields to a database column name
body: <p>I am dealing with Django Rest Framework project and the generic response for my view is not what the app client expects.</p>
  
  <p>The app client expects that the filed of the related models, appears as they are in the database. Example given: model City has a foreign key to Country model, represented by a country_id column. </p>
  
  <p>Is there any option to "map" the serializers default fields into a custom one? I have check the Django Rest Framework documentation but I only found "serializer_field_mapping" but I don't know if it will fit my requirements and also I don't know how to use it.</p>
  
  <p>Somehow I got a close approach of it, but only in the case for fetching data --creating / updating threw some errors that I did not get how to manage. :(</p>
  
  <p>Bellow I attach my models.py file, plus the actual output and the desired output. Also, if it is possible, I would like to retrieve data related with Country / Region if exists combined with the database column <strong>field_id</strong> names.</p>
  
  <p>Thanks in advance,</p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>from django.db import models
  from django.contrib.postgres.fields import ArrayField
  
  
  class Country(models.Model):
  
      name = models.CharField(max_length=150, unique=True, blank=False)
  
      class Meta:
          db_table = 'countries'
  
  
  class Region(models.Model):
  
      name = models.CharField(max_length=150, unique=True, blank=False)
      code = models.CharField(max_length=150, blank=True)
  
      class Meta:
          db_table = 'regions'
  
  
  class City(models.Model):
  
      country = models.ForeignKey(Country)
      region = models.ForeignKey(Region, null=True, blank=True, default=None)
      name = models.CharField(max_length=150, unique=True, blank=False)
      postal_codes = ArrayField(models.CharField(max_length=12, blank=True), null=True, blank=True, default=None)
  
      def __str__(self):
          if not self.region:
              return '%s (%s)' % (self.name, self.country.name)
          return '%s, %s (%s)' % (self.name, self.region.name, self.country.name)
  
      class Meta:
          db_table = 'cities'
  </code></pre>
  
  <p><strong>Actual Output:</strong></p>
  
  <pre><code>[
    {
      "id": 1,
      "name": "San Francisco",
      "postal_codes": null,
      "country": 1,
      "region": 1
    },
    {
      "id": 2,
      "name": "Palo Alto",
      "postal_codes": null,
      "country": 1,
      "region": 1
    },
    {
      "id": 3,
      "name": "New York City",
      "postal_codes": null,
      "country": 1,
      "region": 2
    },
    {
      "id": 4,
      "name": "London",
      "postal_codes": null,
      "country": 2,
      "region": null
    }
  ]
  </code></pre>
  
  <p><strong>Desired Output:</strong></p>
  
  <pre><code>[
    {
      "id": 1,
      "country_id": 1,
      "region_id": 1,
      "name": "San Francisco",
      "postal_codes": null
    },
    {
      "id": 2,
      "country_id": 1,
      "region_id": 1,
      "name": "Palo Alto",
      "postal_codes": null
    },
    {
      "id": 3,
      "country_id": 1,
      "region_id": 2,
      "name": "New York City",
      "postal_codes": null
    },
    {
      "id": 4,
      "country_id": 2,
      "region_id": null,
      "name": "London",
      "postal_codes": null
    }
  ]
  </code></pre>