Skip to content

Commit

Permalink
coding refactoring on views.py
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelusc committed Apr 22, 2024
1 parent cfbf6d8 commit 65618a3
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions app/recipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ def perform_create(self, serializer):
serializer.save(user=self.request.user)


class TagViewSet(
class BaseRecipeAttrViewSet(
mixins.DestroyModelMixin, # implement delete method
mixins.UpdateModelMixin, # implement put method
mixins.ListModelMixin, # implement get method
viewsets.GenericViewSet
):
"""Mange tas in the database."""
serializer_class = serializers.TagSerializer
queryset = Tag.objects.all()
"""Base ViewSet for recipe attributes."""
authentication_classes = [TokenAuthentication]
permission_classes = [IsAuthenticated]

Expand All @@ -52,18 +50,13 @@ def get_queryset(self):
return self.queryset.filter(user=self.request.user).order_by('-name')


class IngredientViewSet(
mixins.DestroyModelMixin, # implement delete method``
mixins.UpdateModelMixin, # implement put method
mixins.ListModelMixin, # implement get method
viewsets.GenericViewSet
):
class TagViewSet(BaseRecipeAttrViewSet):
"""Mange tas in the database."""
serializer_class = serializers.TagSerializer
queryset = Tag.objects.all()


class IngredientViewSet(BaseRecipeAttrViewSet):
"""Manage ingredients in the database."""
serializer_class = serializers.IngredientSerializer
queryset = Ingredient.objects.all()
authentication_classes = [TokenAuthentication]
permission_classes = [IsAuthenticated]

def get_queryset(self):
"""Filter queryset for the authenticated user."""
return self.queryset.filter(user=self.request.user).order_by('-name')

0 comments on commit 65618a3

Please sign in to comment.