def post(self, request, pk): school = get_object_or_404(School, pk=pk) serializer = SchoolSerializer(school, data=request.data) if not serializer.is_valid(): return Response({'serializer': serializer, 'school': school}) serializer.save() return redirect('school-list')
def post(self, request): serializer = SchoolSerializer(data=request.data) if not serializer.is_valid():
def get(self, request): serializer = SchoolSerializer()
def get(self, request, pk): school = get_object_or_404(School, pk=pk) serializer = SchoolSerializer(school) return Response({'serializer': serializer, 'school': school})
def post(self, request): serializer = SchoolSerializer(data=request.data) if not serializer.is_valid(): return Response({'serializer': serializer}) serializer.save() return redirect('school-list')
def get(self, request): serializer = SchoolSerializer() return Response({'serializer': serializer})
template_name = 'school_list.html' def get(self, request): queryset = School.objects.all() return Response({'schools': queryset}) class SchoolDetail(APIView): renderer_classes = [TemplateHTMLRenderer] template_name = 'school_detail.html' def get(self, request, pk): school = get_object_or_404(School, pk=pk) serializer = SchoolSerializer(school) return Response({'serializer': serializer, 'school': school}) def post(self, request, pk): school = get_object_or_404(School, pk=pk) serializer = SchoolSerializer(school, data=request.data) if not serializer.is_valid(): return Response({'serializer': serializer, 'school': school}) serializer.save() return redirect('school-list') class SchoolForm(mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView): queryset = School.objects.all() renderer_classes = [TemplateHTMLRenderer]