set value through serializer django

from django.db import models

class YourModel(models.Model):
    your_field = models.CharField(max_length=255)
from rest_framework import serializers
from .models import YourModel

class YourModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = YourModel
        fields = '__all__'
from rest_framework import generics
from .models import YourModel
from .serializers import YourModelSerializer

class YourModelViewSet(generics.UpdateAPIView):
    queryset = YourModel.objects.all()
    serializer_class = YourModelSerializer
from django.urls import path
from .views import YourModelViewSet

urlpatterns = [
    path('your-model/<int:pk>/', YourModelViewSet.as_view(), name='your-model-detail'),
# in your views or viewssets where you want to update the value
from rest_framework.response import Response
from rest_framework import status

# ...

def your_view(request):
    # ...

    instance = YourModel.objects.get(pk=1)  # Replace 1 with the actual ID of your object
    serializer = YourModelSerializer(instance, data={'your_field': 'new_value'}, partial=True)

    if serializer.is_valid():
        return Response(
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)