예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
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)
예제 #4
0
    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)
예제 #5
0
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)
예제 #6
0
 def get(self, request, pk, format=None):
     family = self.get_object(pk)
     serializer = FamilySerializer(family)
     return Response(serializer.data)
예제 #7
0
 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)
예제 #8
0
 def get(self, request, format=None):
     families = Family.objects.all()
     serializer = FamilySerializer(families, many=True)
     return Response(serializer.data)
예제 #9
0
def search_families(request, pattern):
    families = FamilyNameList.search(pattern)
    serializer = FamilySerializer(instance=families, many=True)
    return Response(serializer.data)