gault-millau/apps/comment/views/common.py

35 lines
1.1 KiB
Python

"""Views for app comment."""
from rest_framework import generics
from rest_framework.permissions import AllowAny
from comment.models import Comment
from comment.serializers import common as serializers
class CommentViewMixin:
"""Mixin for Comment views"""
queryset = Comment.objects.order_by('-created')
serializer_class = serializers.CommentSerializer
class CommentListView(CommentViewMixin, generics.ListAPIView):
"""View for retrieving list of comments."""
permission_classes = (AllowAny, )
def get_queryset(self):
"""Override get_queryset method."""
return self.queryset.annotate_is_mine_status(user=self.request.user)
class CommentCreateView(CommentViewMixin, generics.CreateAPIView):
"""View for create new comment."""
serializer_class = serializers.EstablishmentCommentCreateSerializer
class CommentRUD(CommentViewMixin, generics.RetrieveUpdateDestroyAPIView):
"""View for retrieve/update/destroy view."""
def get_queryset(self):
"""Override get_queryset method."""
return self.queryset.by_user(self.request.user)