Add soft delete API for signups

This commit is contained in:
Aarni Halinen
2020-11-07 20:18:59 +02:00
parent 3a58ff0ef1
commit 1fe323cbdd
4 changed files with 39 additions and 3 deletions
+10 -1
View File
@@ -106,7 +106,7 @@ class SignupFormViewSet(ModelViewSet):
class SignupViewSet(ModelViewSet):
queryset = Signup.objects.all()
queryset = Signup.objects.filter(deleted=False)
serializer_class = SignupSerializer
permission_classes = [SignupPermission]
@@ -156,6 +156,15 @@ class SignupViewSet(ModelViewSet):
else:
return JsonResponse(status=404, data={"error": f"SignupForm {id} not found"})
def destroy(self, request, pk=None, *args, **kwargs):
try:
signup = self.get_object()
signup.deleted = True
signup.save()
return JsonResponse(status=200, data={"message": "OK"})
except ObjectDoesNotExist:
return JsonResponse(status=404, data={"error": f"Signup {pk} not found"})
class SavedQuestionsViewSet(ModelViewSet):
queryset = TemplateQuestion.objects.all()