def put(self, request, pk, format=None): project = self.get_object(pk) serializer = NN_modelSerializer(project, data=request.data) if serializer.is_valid(): serializer.save() # inform email for training complete. if serializer.data['status'] == 'finish': mail_subject = '[PetPen Notification] Training job completion' message = render_to_string( 'petpen/training_complete_notify.html', { 'project': project, 'domain': get_current_site(request).domain, }) to_email = project.user.email if to_email: email = EmailMessage(mail_subject, message, to=[to_email]) email.content_subtype = 'html' email.send() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, format=None): serializer = NN_modelSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request, pk, format=None): project = self.get_object(pk) serializer = NN_modelSerializer(project) return Response(serializer.data)
def get(self, request, format=None): projects = NN_model.objects.filter(user=request.user) serializer = NN_modelSerializer(projects, many=True) return Response(serializer.data)