def put(self, request, pk, format=None): family = self.get_object(pk) serializer = FamilySerializer(family, data=request.data, partial=True) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, pak_id): try: pak = Family.objects.get(pk=pak_id) serializer = FamilySerializer(pak, request.data, partial=True) if serializer.is_valid(raise_exception=True): serializer.save() return Response(serializer.data) except Family.DoesNotExist: pak = Family(pk=pak_id) serializer = FamilySerializer(pak, request.data, partial=True) print(request.data) if serializer.is_valid(raise_exception=True): serializer.save() return Response(serializer.data)
class ListFamily(generics.ListCreateAPIView): queryset = FamilySerializer.init_queryset(Family.objects.all()) serializer_class = FamilySerializer permission_classes = [permissions.IsAuthenticated, IsReadOnlyOrCanEdit] def perform_create(self, serializer): serializer.save(owner=self.request.user)
def get(self, request, family_id): try: family = Family.objects.get(pk=family_id) except ObjectDoesNotExist: raise Http404 serializer = FamilySerializer(instance=family) return Response(serializer.data)
def list_family_of_individual(request, pk): if request.method != 'GET': return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) try: individual = Individual.objects.get(pk=pk) except Snippet.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) families = individual.partner_in_families.all() serializer = FamilySerializer(families, many=True) return Response(serializer.data)
def get(self, request, pk, format=None): family = self.get_object(pk) serializer = FamilySerializer(family) return Response(serializer.data)
def post(self, request, format=None): serializer = FamilySerializer(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, format=None): families = Family.objects.all() serializer = FamilySerializer(families, many=True) return Response(serializer.data)
def search_families(request, pattern): families = FamilyNameList.search(pattern) serializer = FamilySerializer(instance=families, many=True) return Response(serializer.data)