How do I the value for a foreign key to show up in Django Rest
<p>I want my output json to show the value of a the record that the foreign key is pointing to instead of the key instead.</p>

<p>For example i want this to show up:</p>

<pre><code>[
    {
        "id": 1,
        "brand": "ATL Motors",
        "package": "Full Page",
        "newspaper": "Gleaner",
        "cost": 22000,
        "objective": "Brand Awareness",
        "ad_date": "2016-10-01",
        "created_on": "2016-10-07T20:21:52Z"
    }
</code></pre>

<p>]</p>

<p>Instead of this:</p>

<pre><code>[
    {
        "id": 1,
        "brand": 2,
        "package": "Full Page",
        "newspaper": 1,
        "cost": 22000,
        "objective": "Brand Awareness",
        "ad_date": "2016-10-01",
        "created_on": "2016-10-07T20:21:52Z"
    }
]
</code></pre>

<p>Here is my models.py file:</p>

<pre><code>from django.db import models
from django.utils import timezone


class Brand(models.Model):
    name = models.CharField(max_length=100)
    description = models.TextField()
    website = models.URLField()
    created_on = models.DateTimeField(default=timezone.now())

    def __str__(self):
        return self.name


class Newspaper(models.Model):
    name = models.CharField(max_length=200)
    created_on = models.DateTimeField(default=timezone.now())

    def __str__(self):
        return self.name


class PurchasedAd(models.Model):
    brand = models.ForeignKey(Brand, on_delete=models.CASCADE)
    package = models.CharField(max_length=350)
    newspaper = models.ForeignKey(Newspaper, on_delete=models.CASCADE)
    cost = models.IntegerField()
    objective = models.TextField()
    ad_date = models.DateField()
    created_on = models.DateTimeField(default=timezone.now())

    def __str__(self):
        string = "{} - {}".format(self.brand, self.objective)
        return string
</code></pre>

<p>Here is my serializer.py file:</p>

<pre><code>from rest_framework import serializers
from . import models


class BrandSerializer(serializers.ModelSerializer):
    class Meta:
        fields = (
            'id',
            'name',
            'description',
            'website',
            'created_on',
        )
        model = models.Brand


class PurchasedAdSerializer(serializers.ModelSerializer):
    class Meta:
        fields = (
            'id',
            'brand',
            'package',
            'newspaper',
            'cost',
            'objective',
            'ad_date',
            'created_on',
        )
        model = models.PurchasedAd
</code></pre>

<p>Here is my views.py file:</p>

<pre><code>from rest_framework import generics
from . import models
from . import serializers


class ListBrand(generics.ListAPIView):
    queryset = models.Brand.objects.all()
    serializer_class = serializers.BrandSerializer


class ListAds(generics.ListAPIView):
    queryset = models.PurchasedAd.objects.all()
    serializer_class = serializers.PurchasedAdSerializer
</code></pre>

<p>PLEASE HELP!!</p>

<p>You can use <a href="http://www.django-rest-framework.org/api-guide/relations/#stringrelatedfield" rel="nofollow">StringRelatedField</a></p>

<blockquote>
  <p>StringRelatedField may be used to represent the target of the
  relationship using its <strong>unicode</strong> method.</p>
</blockquote>

<pre><code>class PurchasedAdSerializer(serializers.ModelSerializer):
    newspaper = serializers.StringRelatedField()

    class Meta:
        fields = (
            'id',
            'brand',
            'package',
            'newspaper',
            'cost',
            'objective',
            'ad_date',
            'created_on',
        )
        model = models.PurchasedAd
</code></pre>

python django django-rest-framework