DRF - where to modify serializer response?
<p>I need to encrypt/decrypt data that is being served from Django Rest Framework.</p>

<p>models.py</p>

<pre><code>class Widget(models.Model):
    title = models.CharField(max_length=100)
    description = models.CharField(max_length=1024)
    username = models.CharField(max_length=50)
    code = models.CharField(max_length=1024)
    owner = models.ForeignKey('MyAppUser', related_name='MyAppUser_owner')
    list = models.ForeignKey('WidgetList')
</code></pre>

<p>Depending on the user logged in the key would be different.</p>

<p>serializers.py</p>

<pre><code>class WidgetSerializer(serializers.ModelSerializer):
    owner = serializers.ReadOnlyField(source='owner.username')
    list = serializers.CharField(source='list.name')

    class Meta:
        model=Widget
        fields = ('id', 'title', 'description', 'username', 'code', 'owner', 'list')
</code></pre>

<p>views.py</p>

<pre><code>class WidgetList(generics.ListCreateAPIView):
    queryset = Widget.objects.all()
    serializer_class = WidgetSerializer
    filter_class = WidgetFilter

    def get_queryset(self):
        owner = self.request.user
        return super(WidgetList, self).get_queryset().filter(owner=self.request.user)
</code></pre>

<p>so depending on the user logged in (userkey is different per user) I need to run the following code - </p>

<p>GET</p>

<pre><code>for object in queryset:
    object.code = decrypt_code(masterkey,
                                       userkey,
                                       object.code)
</code></pre>

<p>POST</p>

<pre><code>object.code = encrypt_code(masterkey,
                                   userkey,
                                   object.code)
</code></pre>

<p>How do I integrate this code into a view without breaking the existing filter code or how would I integrate it into a serializer?</p>