title: Filtering using viewsets in django rest framework
body: <p>Please consider these three models:</p>
  
  <pre><code>class Movie(models.Model):
      name = models.CharField(max_length=254, unique=True)
      language = models.CharField(max_length=14)
      synopsis = models.TextField()
  
  class TimeTable(models.Model):
      date = models.DateField()
  
  class Show(models.Model):
      day = models.ForeignKey(TimeTable)
      time = models.TimeField(choices=CHOICE_TIME)
      movie = models.ForeignKey(Movie)
  
      class Meta:
          unique_together = ('day', 'time')
  </code></pre>
  
  <p>And each of them has their serializers:</p>
  
  <pre><code>class MovieSerializer(serializers.HyperlinkedModelSerializer):
      movie_id = serializers.IntegerField(read_only=True, source="id")
  
      class Meta:
          model = Movie
          fields = '__all__'    
  
  class TimeTableSerializer(serializers.HyperlinkedModelSerializer):
      class Meta:
          model = TimeTable
          fields = '__all__'
  
  
  class ShowSerializer(serializers.HyperlinkedModelSerializer):
      class Meta:
          model = Show
          fields = '__all__'
  </code></pre>
  
  <p>And their routers</p>
  
  <pre><code>router.register(r'movie-list', views.MovieViewSet)
  router.register(r'time-table', views.TimeTableViewSet)
  router.register(r'show-list', views.ShowViewSet)        
  </code></pre>
  
  <p>Now I would like to get all the TimeTable objects (i.e. date list) by filtering all the Show objects by a specific movie object. This code seems to be the working and getting the list like I want it</p>
  
  <pre><code>m = Movie.objects.get(id=request_id)
  TimeTable.objects.filter(show__movie=m).distinct()
  </code></pre>
  
  <p>But I have no clue how to use this in django rest framework? I tried doing this way (which I am  pretty sure its wrong), and I am getting error:</p>
  
  <p>views.py:</p>
  
  <pre><code>class DateListViewSet(viewsets.ModelViewSet, movie_id):
      movie = Movie.objects.get(id=movie_id)
      queryset = TimeTable.objects.filter(show__movie=movie).distinct()
      serializer_class = TimeTableSerializer
  </code></pre>
  
  <p>urls.py:</p>
  
  <pre><code>router.register(r'date-list/(?P&lt;movie_id&gt;.+)/', views.DateListViewSet)
  </code></pre>
  
  <p>error:</p>
  
  <blockquote>
    <p>class DateListViewSet(viewsets.ModelViewSet, movie_id):
    NameError: name 'movie_id' is not defined</p>
  </blockquote>
  
  <p>How can I filter using viewsets in django rest framework? Or if there is any other prefered way than please list it out. Thank you.</p>