title: Django change value before save in ModelViewSet
body: <p>I am new to Django (and the REST framework) but I am struggling to update a value before save. Right now I am using a simple ModelViewSet to update a record. Everything works, but the value doesnt get updated if I create an item in de admin site.</p>
  <p>Code of the view is as follows:</p>
  <pre><code>class OauthProviderViewSet(viewsets.ModelViewSet):
      queryset = OauthProvider.objects.all()
      serializer_class = OauthProviderSerializer 
      authentication_classes = [SessionAuthentication, BasicAuthentication]
      permission_classes = [IsAdminUser]
  
      def perform_create(self, serializer):
          changed_credentials = &quot;test&quot; + self.request.credentials
          serializer.save(credentials=changed_credentials)
  </code></pre>
  <p>I just want to pre-pend the word test to the credentials field.</p>
  <p>EDIT: a post was suggested that explained the difference between the serializer's create and the model's create function. Funny thing is that 1. I dont understand the difference, but 2. Both of them didnt work.</p>
  <p>EDIT2: Tried in the serializer with something I found, again everything works flawlessly but my snippet isnt executed:</p>
  <pre><code>class OauthProviderSerializer(serializers.ModelSerializer):
      class Meta:
          model = OauthProvider
          #fields = ['id', 'title', 'author']
          fields = &quot;__all__&quot;
  
      def create(self, instance, validated_data):
          validated_data['credentials'] = &quot;test&quot; + validated_data['credentials']
          return super(OauthProviderSerializer, self).create(validated_data)
  </code></pre>
  <p>EDIT3: I found the issue (partly). I was using the admin screen to create the values but that functionality doesnt use views or serializers. If I use the normal POST method my code gets executed.</p>
  <p>Am I right that for this functionality it is best to update the ModelViewSet's perform_create method? According to this url: <a href="https://simpleisbetterthancomplex.com/tutorial/2019/04/07/how-to-save-extra-data-to-a-django-rest-framework-serializer.html" rel="nofollow noreferrer">https://simpleisbetterthancomplex.com/tutorial/2019/04/07/how-to-save-extra-data-to-a-django-rest-framework-serializer.html</a></p>