This QueryDict instance is immutable

后端 未结 5 1072
夕颜
夕颜 2020-12-30 06:10

I have a Branch model with a foreign key to account (the owner of the branch):

class Branch(SafeDeleteModel):
    _safedelete_policy = SOFT_DELETE_CASCADE
           


        
5条回答
  •  孤城傲影
    2020-12-30 06:20

    Do Simple:

    #views.py
    from rest_framework import generics
    
    
    class Login(generics.CreateAPIView):
        serializer_class = MySerializerClass
        def create(self, request, *args, **kwargs):
            request.data._mutable = True
            request.data['username'] = "example@mail.com"
            request.data._mutable = False
    
    #serializes.py
    from rest_framework import serializers
    
    
    class MySerializerClass(serializers.Serializer):
        username = serializers.CharField(required=False)
        password = serializers.CharField(required=False)
        class Meta:
            fields = ('username', 'password')
    

提交回复
热议问题