
from rest_framework import viewsets
from rest_framework.filters import DjangoObjectPermissionsFilter

from .. import (
    models,
    permissions,
)
from ..serializers import (
    primarykey as serializers
)


class MovieViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = models.Movie.objects.all()
    serializer_class = serializers.MovieSerializer


class GenreViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = models.Genre.objects.all()
    serializer_class = serializers.GenreSerializer


class WatchlistViewSet(viewsets.ModelViewSet):
    queryset = models.Watchlist.objects.all()
    serializer_class = serializers.WatchlistSerializer
    filter_backends = [
        DjangoObjectPermissionsFilter,
    ]
    permission_classes = [
        permissions.DjangoObjectPermissions,
    ]


class ResumeViewSet(viewsets.ModelViewSet):
    queryset = models.Resume.objects.all()
    serializer_class = serializers.ResumeSerializer
    filter_backends = [
        DjangoObjectPermissionsFilter,
    ]
    permission_classes = [
        permissions.DjangoObjectPermissions,
    ]


class RatingViewSet(viewsets.ModelViewSet):
    queryset = models.Rating.objects.all()
    serializer_class = serializers.RatingSerializer


from rest_framework import viewsets, filters

from .. import (
    models,
    permissions,
)
from ..serializers import (
    primarykey as serializers
)


class MovieViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = models.Movie.objects.all()
    serializer_class = serializers.MovieSerializer
    filter_backends = (
        filters.OrderingFilter,
    )
    ordering_fields = (
        'title',
        'released',
        'runtime',
    )


class GenreViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = models.Genre.objects.all()
    serializer_class = serializers.GenreSerializer
    filter_backends = (
        filters.OrderingFilter,
    )
    ordering_fields = (
        'name',
    )


class WatchlistViewSet(viewsets.ModelViewSet):
    queryset = models.Watchlist.objects.all()
    serializer_class = serializers.WatchlistSerializer
    filter_backends = (
        filters.DjangoObjectPermissionsFilter,
    )
    permission_classes = (
        permissions.DjangoObjectPermissions,
    )


class ResumeViewSet(viewsets.ModelViewSet):
    queryset = models.Resume.objects.all()
    serializer_class = serializers.ResumeSerializer
    filter_backends = (
        filters.DjangoObjectPermissionsFilter,
    )
    permission_classes = (
        permissions.DjangoObjectPermissions,
    )


class RatingViewSet(viewsets.ModelViewSet):
    queryset = models.Rating.objects.all()
    serializer_class = serializers.RatingSerializer

Add ordering filters for primary key based api.
Add ordering filters for primary key based api.

  
- from rest_framework import viewsets
+ from rest_framework import viewsets, filters
- from rest_framework.filters import DjangoObjectPermissionsFilter
  
  from .. import (
      models,
      permissions,
  )
  from ..serializers import (
      primarykey as serializers
  )
  
  
  class MovieViewSet(viewsets.ReadOnlyModelViewSet):
      queryset = models.Movie.objects.all()
      serializer_class = serializers.MovieSerializer
+     filter_backends = (
+         filters.OrderingFilter,
+     )
+     ordering_fields = (
+         'title',
+         'released',
+         'runtime',
+     )
  
  
  class GenreViewSet(viewsets.ReadOnlyModelViewSet):
      queryset = models.Genre.objects.all()
      serializer_class = serializers.GenreSerializer
+     filter_backends = (
+         filters.OrderingFilter,
+     )
+     ordering_fields = (
+         'name',
+     )
  
  
  class WatchlistViewSet(viewsets.ModelViewSet):
      queryset = models.Watchlist.objects.all()
      serializer_class = serializers.WatchlistSerializer
-     filter_backends = [
+     filter_backends = (
-         DjangoObjectPermissionsFilter,
+         filters.DjangoObjectPermissionsFilter,
-     ]
+     )
-     permission_classes = [
+     permission_classes = (
          permissions.DjangoObjectPermissions,
-     ]
+     )
  
  
  class ResumeViewSet(viewsets.ModelViewSet):
      queryset = models.Resume.objects.all()
      serializer_class = serializers.ResumeSerializer
-     filter_backends = [
+     filter_backends = (
-         DjangoObjectPermissionsFilter,
+         filters.DjangoObjectPermissionsFilter,
-     ]
+     )
-     permission_classes = [
+     permission_classes = (
          permissions.DjangoObjectPermissions,
-     ]
+     )
  
  
  class RatingViewSet(viewsets.ModelViewSet):
      queryset = models.Rating.objects.all()
      serializer_class = serializers.RatingSerializer
  
Add ordering filters for primary key based api.
## Code Before:

from rest_framework import viewsets
from rest_framework.filters import DjangoObjectPermissionsFilter

from .. import (
    models,
    permissions,
)
from ..serializers import (
    primarykey as serializers
)


class MovieViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = models.Movie.objects.all()
    serializer_class = serializers.MovieSerializer


class GenreViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = models.Genre.objects.all()
    serializer_class = serializers.GenreSerializer


class WatchlistViewSet(viewsets.ModelViewSet):
    queryset = models.Watchlist.objects.all()
    serializer_class = serializers.WatchlistSerializer
    filter_backends = [
        DjangoObjectPermissionsFilter,
    ]
    permission_classes = [
        permissions.DjangoObjectPermissions,
    ]


class ResumeViewSet(viewsets.ModelViewSet):
    queryset = models.Resume.objects.all()
    serializer_class = serializers.ResumeSerializer
    filter_backends = [
        DjangoObjectPermissionsFilter,
    ]
    permission_classes = [
        permissions.DjangoObjectPermissions,
    ]


class RatingViewSet(viewsets.ModelViewSet):
    queryset = models.Rating.objects.all()
    serializer_class = serializers.RatingSerializer

## Instruction:
Add ordering filters for primary key based api.
## Code After:

from rest_framework import viewsets, filters

from .. import (
    models,
    permissions,
)
from ..serializers import (
    primarykey as serializers
)


class MovieViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = models.Movie.objects.all()
    serializer_class = serializers.MovieSerializer
    filter_backends = (
        filters.OrderingFilter,
    )
    ordering_fields = (
        'title',
        'released',
        'runtime',
    )


class GenreViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = models.Genre.objects.all()
    serializer_class = serializers.GenreSerializer
    filter_backends = (
        filters.OrderingFilter,
    )
    ordering_fields = (
        'name',
    )


class WatchlistViewSet(viewsets.ModelViewSet):
    queryset = models.Watchlist.objects.all()
    serializer_class = serializers.WatchlistSerializer
    filter_backends = (
        filters.DjangoObjectPermissionsFilter,
    )
    permission_classes = (
        permissions.DjangoObjectPermissions,
    )


class ResumeViewSet(viewsets.ModelViewSet):
    queryset = models.Resume.objects.all()
    serializer_class = serializers.ResumeSerializer
    filter_backends = (
        filters.DjangoObjectPermissionsFilter,
    )
    permission_classes = (
        permissions.DjangoObjectPermissions,
    )


class RatingViewSet(viewsets.ModelViewSet):
    queryset = models.Rating.objects.all()
    serializer_class = serializers.RatingSerializer
