-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
27 lines (21 loc) · 841 Bytes
/
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
from django.shortcuts import render
from rest_framework.generics import GenericAPIView
from rest_framework.renderers import TemplateHTMLRenderer
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from .models import Topic
from .serializers import TopicSerializer
class TopicViewSet(ModelViewSet):
lookup_field = 'id'
queryset = Topic.objects.all()
serializer_class = TopicSerializer
class ShowTopicResources(GenericAPIView):
lookup_field = 'id'
queryset = Topic.objects.all()
serializer_class = TopicSerializer
renderer_classes = [TemplateHTMLRenderer]
template_name = 'topic/show.html'
def get(self, request, id):
instance = self.get_object()
serializer = self.get_serializer(instance)
return Response({'topics': serializer.data})