[Python] Django REST serializer: create object without saving

Discussão em 'Python' iniciado por Stack, Maio 29, 2025.

  1. Stack

    Stack Membro Participativo

    I have started to play with the Django REST framework. What I am trying to do is to POST a request with some JSON, create a Django Model object out of it, and use the object without saving it. My Django model is called SearchRequest. What I have is:

    @api_view(['POST'])
    def post_calculation(request):
    if request.method == 'POST':
    #JSON to serializer object
    serializer = SearchRequestSerializer(data=request.data)
    if (serializer.is_valid() == False):
    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    mySearchRequestObject = serializer.save()


    This does create a SearchRequest object, however saves it into the database right away. I would need it without saving.

    Continue reading...

Compartilhe esta Página