title: Django Rest Framework: Custom Views
body: <p>i have a django installation with currently two apps ( common / destinations ) and i want to create custom api views across these apps.</p>
  <p>in common i have a model country</p>
  <p>models.py app common</p>
  <pre><code>from django.db import models
  
  # Create your models here.
  
  class Country(models.Model):
      CONTINENTS = (
          ('Europe', 'Europe'),
          ('Asia', 'Asia'),
          ('Africa', 'Africa'),
          ('northamerica', 'North America'),
          ('southamerica', 'South America'),
          ('australia', 'Australia')
      )
      name = models.CharField(max_length=120)
      code = models.CharField(max_length=2)
      continent = models.CharField(max_length=11, choices=CONTINENTS)
      content = models.TextField()
      image = models.FileField()
  </code></pre>
  <p>models.py app destination</p>
  <pre><code>from django.db import models
  
  # Create your models here.
  
  class Destination(models.Model):
      name = models.CharField(max_length=120)
      code = models.CharField(max_length=3)
      country = models.ForeignKey(&quot;common.Country&quot;, on_delete=models.CASCADE)
      image = models.FileField()
  </code></pre>
  <p>serializers.py app destination</p>
  <pre><code>from rest_framework import serializers
  from common.serializers import CountrySerializer
  from .models import Destination 
  
  class DestinationSerializer(serializers.ModelSerializer):
  
  country = CountrySerializer()
  
  class Meta:
      model = Destination
      fields = (&quot;id&quot;, &quot;name&quot;, &quot;code&quot;, &quot;country&quot;, &quot;image&quot;)
  </code></pre>
  <p>views.py app destination</p>
  <pre><code>from rest_framework import views
  from rest_framework.response import Response
  from .serializers import DestinationSerializer, ImageSerializer
  from .models import Destination
  
  # Create your views here.
  
  class DestinationView(views.APIView):
      def get(self, request, code):
          destination =  Destination.objects.filter(code=code.upper())
          if destination:
              serializer = DestinationSerializer(destination, many=True)
              return Response(status=200, data=serializer.data)
          return Response(status=400, data={&quot;Destination not found&quot;})
  </code></pre>
  <p>When i make a API call /api/destination/PMI everything works. i get my destination from destination app and country from common app.</p>
  <pre><code>**GET /api/destination/**
  
  HTTP 200 OK
  Allow: GET, HEAD, OPTIONS
  Content-Type: application/json
  Vary: Accept
  
  [
      {
          &quot;id&quot;: 1,
          &quot;name&quot;: &quot;Palma de Mallorca&quot;,
          &quot;code&quot;: &quot;PMI&quot;,
          &quot;country&quot;: {
              &quot;id&quot;: 1,
              &quot;name&quot;: &quot;Spain&quot;,
              &quot;code&quot;: &quot;ES&quot;,
              &quot;continent&quot;: &quot;Europe&quot;,
              &quot;content&quot;: &quot;Lorem Ipsum&quot;,
              &quot;image&quot;: &quot;http://localhost:1000/media/logo.svg&quot;
          },
          &quot;image&quot;: &quot;http://localhost:1000/media/2020-08-03_07-40.png&quot;
      }
  ]
  </code></pre>
  <p>Now i want to create a view which only returns the images from common / destination</p>
  <p>e.g.</p>
  <pre><code>GET **/api/destination/pmi/image**
  HTTP 200 OK
  Allow: GET, HEAD, OPTIONS
  Content-Type: application/json
  Vary: Accept
  [
      {
           &quot;code&quot;: &quot;pmi&quot;,
           &quot;destination_image&quot; : &quot;image.png&quot;,
           &quot;country_image&quot; : &quot;country.png&quot; 
      }
  ]
  </code></pre>
  <p>how, if possible, can i achieve that?</p>