Please consider these three models: 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') And each of them has their serializers: 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__' And their routers router.register(r'movie-list', views.MovieViewSet) router.register(r'time-table', views.TimeTableViewSet) router.register(r'show-list', views.ShowViewSet) 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 m = Movie.objects.get(id=request_id) TimeTable.objects.filter(show__movie=m).distinct() 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: views.py: class DateListViewSet(viewsets.ModelViewSet, movie_id): movie = Movie.objects.get(id=movie_id) queryset = TimeTable.objects.filter(show__movie=movie).distinct() serializer_class = TimeTableSerializer urls.py: router.register(r'date-list/(?P<movie_id>.+)/', views.InTheatersViewSet) How can I filter using viewsets in django rest framework? Or if there is any prefered way than please list it out. Thank you. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAM4YLWJZ0tC356VFrcEk8390M59-dG-P93g_2P5XWsoQO%2BPwdQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.