Home > Software design >  How to avoid data being stored in database using django rest framework
How to avoid data being stored in database using django rest framework

Time:11-28

I have created a Django REST framework API. For that I have created a model and a serializer. It is working fine. I want to know if there is a way that my input would not store in database. Currently, my inputs are stored in sqlite3 database. The reason why I want to do that the user input value via php form. I have to take 1 value from that form and do some modifications on it and return the value. Thats why I don't think I need a db for my Django project.

Here is code

models.py

class MyModel(models.Model):
    value=models.IntegerField()

serializers.py

class MySerializer(serializers.ModelSerializer):
    class Meta:
        model=MyModel
        fields='__all__'

views.py

class MyViews(APIView):
    def post(self, request):
        serializer = MySerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response({"status": "success", "data": serializer.data}, status=status.HTTP_200_OK)
        else:
            return Response({"status": "error", "data": serializer.errors}, status=status.HTTP_400_BAD_REQUEST)

urls.py

urlpatterns = [
    path('api', VideoUploadViews.as_view())
]

CodePudding user response:

Remove your serializer.save() call and it should no longer be saving your serialized data to your database.

  • Related