-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathviews.py
51 lines (41 loc) · 1.48 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from django.shortcuts import render
# Create your views here.
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import generics, mixins, permissions, status
from .models import Blog
from .serializers import BlogSerializer, ABlogSerializer
from user.permissions import *
class BlogAPIView(mixins.CreateModelMixin, generics.ListAPIView):
permission_classes = [AuthenticatedOrReadOnly]
#authentication_classes = [SessionAuthentication]
serializer_class = BlogSerializer
#passed_id = None
#running queries and stuff
def get(self, request):
return Response({
'status':
'OK',
'result':
BlogSerializer(Blog.objects.all(), many=True).data
})
class ABlogAPIView(mixins.CreateModelMixin, generics.ListAPIView):
permission_classes = [AuthenticatedOrReadOnly]
#authentication_classes = [SessionAuthentication]
serializer_class = ABlogSerializer
#passed_id = None
#running queries and stuff
def get(self, request, slug):
qs = Blog.objects.filter(slug=slug)
if qs.exists():
return Response({
'status': 'OK',
'result': ABlogSerializer(qs[0]).data
})
else:
return Response(
{
'status': 'FAILED',
'error': 'Requested Blog doesn\'t exists.'
},
status=status.HTTP_400_BAD_REQUEST)