title: Django Rest Framework filtering data by url
body: <p>I want to filter my Django Rest Framework serialized data by the URL provided by user. Here is my code:</p>
  
  <p>models.py:</p>
  
  <pre><code>class Airline(models.Model):
      name = models.CharField(max_length=10, blank=True, null=True)
      code = models.CharField(max_length=2, blank=True, null=True)
  
      def __str__(self):
          return self.name
  
  class FinancialData(models.Model): 
      airline = models.ForeignKey(Airline)
      mainline_revenue = models.DecimalField(max_digits=7, decimal_places=2)
      regional_revenue = models.DecimalField(max_digits=7, decimal_places=2)
      other_revenue = models.DecimalField(max_digits=7, decimal_places=2)
      total_revenue = models.DecimalField(max_digits=7, decimal_places=2)
  
          def __str__(self):
          return str(self.mainline_revenue)
  </code></pre>
  
  <p>view.py:</p>
  
  <pre><code>class ListAirlineFinancialData(generics.ListAPIView):
      serializer_class = FinancialDataSerializer
  
      def get_queryset(self, *args, **kwargs):
          query_list = FinancialData.objects.filter(pk=airline_id)
  </code></pre>
  
  <p>urls.py: </p>
  
  <pre><code>urlpatterns = [
      url(r'^api/v1/airline/(?P&lt;pk&gt;\d+)/$', views.ListAirlineFinancialData.as_view(), name='airline_financial_data'),
  ]
  </code></pre>
  
  <p>What should I code in views to filter my data for the following URL.
  <a href="http://localhost:8000/api/v1/airline/3/" rel="nofollow noreferrer">http://localhost:8000/api/v1/airline/3/</a></p>
  
  <p>At this moment Django is giving me an error that <strong>name 'airline_id' is not defined</strong> I can understand that it wants me to pass on airline_id which is in my database but I really dont know how to do it. What code should I write in views.py that it filters all the data for the airline any particular id. Thanks</p>