title: Django Rest Framework Calculations in Serializer?
body: <p>I'm working with a finance application, and due to the way that floating point math works, have decided to store all values in the database as cents (so dollar amount * 100). I have been banging my head against a wall to get the serializer to perform two calculations for me. On create/update accept a float value but then before saving to the database do value*100. Then on get, do value/100.</p>
  
  <p>I got it half working using a <code>SerializerMethodField</code>, but that seemed to remove my ability to do create/update actions. I also at one point had something that kind of worked for create/update by changing the <code>serializer.save()</code> method in the view and adding an <code>IntegerField</code> validator on the field, but then that broke the <code>SerializerMethodField</code>.</p>
  
  <p>In short, I'm stuck. lol</p>
  
  <p>Here is my very simple model:</p>
  
  <pre><code>class Items(models.Model):
      user = models.ForeignKey(
          'CustomUser',
          on_delete=models.CASCADE,
      )
      name = models.CharField(max_length=60)
      total = models.IntegerField()
  </code></pre>
  
  <p>My views for this item:</p>
  
  <pre><code>class GetItems(generics.ListCreateAPIView):
      serializer_class = ItemsSerializer
      permission_classes = [permissions.IsAuthenticated, IsAuthorOrDenied]
      user = serializers.HiddenField(default=serializers.CurrentUserDefault(), )
  
      def get_queryset(self):
          user = self.request.user
          return Items.objects.filter(user=user)
  
      def perform_create(self, serializer):
          serializer.save(user=self.request.user)
  
  
  class SingleItem(generics.RetrieveUpdateDestroyAPIView):
      serializer_class = ItemsSerializer
      permission_classes = [permissions.IsAuthenticated, IsAuthorOrDenied]
      user = serializers.HiddenField(default=serializers.CurrentUserDefault(), )
  
      def get_queryset(self):
          user = self.request.user
          return Items.objects.filter(user=user)
  
      def perform_update(self, serializer):
          serializer.save(user=self.request.user)
  </code></pre>
  
  <p>And my serializer</p>
  
  <pre><code>class ItemsSerializer(serializers.ModelSerializer):
      class Meta:
          fields = ('id', 'name', 'budget_total')
          model = models.Items
  </code></pre>
  
  <p>I feel like I should be doing more in my Serializer and less in my views, but that may be a completely different question all together.</p>
  
  <p>Thanks in advance for the help!</p>