# Path: Blog/posts/api/views.py
# class PostListAPIView(ListAPIView):
#     serializer_class = PostListSerializer
#     filter_backends = [OrderingFilter]
#     permission_classes = [AllowAny]
#     pagination_class = PostLimitOffsetPagination
# 
#     def get_queryset(self, *args, **kwargs):
#         query_list = Post.objects.all()
#         query = self.request.GET.get("q")
#         if query:
#             query_list = query_list.filter(
#                 Q(title__icontains=query) |
#                 Q(user__first_name__icontains=query) |
#                 Q(user__last_name__icontains=query) |
#                 Q(content__icontains=query)
#             ).distinct()
#         return query_list
# 
# class PostDetailAPIView(RetrieveAPIView):
#     queryset = Post.objects.all()
#     serializer_class = PostDetailSerializer
#     permission_classes = [AllowAny]
#     lookup_field = "slug"
#     # for reference
#     # lookup_url_kwarg = "abc"
# 
# class PostDeleteAPIView(DestroyAPIView):
#     queryset = Post.objects.all()
#     serializer_class = PostDetailSerializer
#     permission_classes = [IsOwnerOrReadOnly]
#     lookup_field = "slug"
# 
# class PostUpdateAPIView(RetrieveUpdateAPIView):
#     queryset = Post.objects.all()
#     serializer_class = PostCreateUpdateSerializer
#     lookup_field = "slug"
#     permission_classes = [IsOwnerOrReadOnly]
# 
# class PostCreateAPIView(CreateAPIView):
#     queryset = Post.objects.all()
#     serializer_class = PostCreateUpdateSerializer
#     permission_classes = [IsAdminUser]
# 
#     def perform_create(self, serializer):
#         serializer.save(user=self.request.user)


from django.conf.urls import url
from .views import PostListAPIView, PostDetailAPIView, PostDeleteAPIView, PostUpdateAPIView, PostCreateAPIView

urlpatterns = [
    url(r"^$", PostListAPIView.as_view(), name="list"),
    url(r"^(?P<slug>[\w-]+)/$", PostDetailAPIView.as_view(), name="detail"),
    url(r"^create$", PostCreateAPIView.as_view(), name="create"),
    url(r"^(?P<slug>[\w-]+)/delete/$", PostDeleteAPIView.as_view(), name="delete"),
    url(r"^(?P<slug>[\w-]+)/edit/$", PostUpdateAPIView.as_view(), name="update"),

# Path: Blog/posts/api/views.py
# class PostListAPIView(ListAPIView):
#     serializer_class = PostListSerializer
#     filter_backends = [OrderingFilter]
#     permission_classes = [AllowAny]
#     pagination_class = PostLimitOffsetPagination
# 
#     def get_queryset(self, *args, **kwargs):
#         query_list = Post.objects.all()
#         query = self.request.GET.get("q")
#         if query:
#             query_list = query_list.filter(
#                 Q(title__icontains=query) |
#                 Q(user__first_name__icontains=query) |
#                 Q(user__last_name__icontains=query) |
#                 Q(content__icontains=query)
#             ).distinct()
#         return query_list
# 
# class PostDetailAPIView(RetrieveAPIView):
#     queryset = Post.objects.all()
#     serializer_class = PostDetailSerializer
#     permission_classes = [AllowAny]
#     lookup_field = "slug"
#     # for reference
#     # lookup_url_kwarg = "abc"
# 
# class PostDeleteAPIView(DestroyAPIView):
#     queryset = Post.objects.all()
#     serializer_class = PostDetailSerializer
#     permission_classes = [IsOwnerOrReadOnly]
#     lookup_field = "slug"
# 
# class PostUpdateAPIView(RetrieveUpdateAPIView):
#     queryset = Post.objects.all()
#     serializer_class = PostCreateUpdateSerializer
#     lookup_field = "slug"
#     permission_classes = [IsOwnerOrReadOnly]
# 
# class PostCreateAPIView(CreateAPIView):
#     queryset = Post.objects.all()
#     serializer_class = PostCreateUpdateSerializer
#     permission_classes = [IsAdminUser]
# 
#     def perform_create(self, serializer):
#         serializer.save(user=self.request.user)


# Path: Blog/posts/api/urls.py
from django.conf.urls import url
from .views import PostListAPIView, PostDetailAPIView, PostDeleteAPIView, PostUpdateAPIView, PostCreateAPIView


urlpatterns = [
    url(r"^$", PostListAPIView.as_view(), name="list"),
    url(r"^(?P<slug>[\w-]+)/$", PostDetailAPIView.as_view(), name="detail"),
    url(r"^create$", PostCreateAPIView.as_view(), name="create"),
    url(r"^(?P<slug>[\w-]+)/delete/$", PostDeleteAPIView.as_view(), name="delete"),
    url(r"^(?P<slug>[\w-]+)/edit/$", PostUpdateAPIView.as_view(), name="update"),

]