def put(self, request, pk, format=None): item = self.get_object(pk) serializer = EhfpiSerializer(item, data=request.DATA) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request, format=None): parms = {} #query type must be in field, for item,value in request.GET.items(): for item1 in field: if item1.upper() == item.upper(): #ignore case valuePrimary = value.split(',') arr = [] for val in valuePrimary: #remove space etc arr.append(val.strip()) if '' in arr: #remove only '' arr.remove('') if len(arr): #has a parms, otherwise, we remove this parms[item1] = arr #construct Q query object qTotal = Q() for key,value in parms.items(): qTotal = qTotal & Q(**{key+'__in': value}) item = allEHFPI.objects.filter(qTotal) serializer = EhfpiSerializer(item, many=True) return Response(serializer.data)
def post(self, request, format=None): serializer = EhfpiSerializer(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): item = self.get_object(pk) serializer = EhfpiSerializer(item) return Response(serializer.data)
def get(self, request, format=None): item = allEHFPI.objects.all() serializer = EhfpiSerializer(item, many=True) return Response(serializer.data)