def post(self, request, format=None): serializer = ShopSerializer(data=request.data) if serializer.is_valid(): print('true') serializer.save(owner=request.user) return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, pk, format=None): shop_instance = get_object_or_404(Shop, pk=pk) serializer = ShopSerializer(shop_instance, data=request.data) if serializer.is_valid(): print('true') serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def create(self, request, *args, **kwargs): serializer = ShopSerializer(data={ 'name': request.data['name'], 'shop_owner_id': request.user.id }) 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)