title: Django Rest Framework read-write flat serializer using to_internal_value() and to_representation()
body: <p>I've successfully implemented writable-nested-serializer following the drf documentation and I've also been able to change its representation using to_representation() method to look cleaner.</p>
  
  <p>\initial data structure where POST works fine with modified crete()</p>
  
  <pre><code>{
      "id": 1033,
      "client": {
          "client_name": "BAC"
      },
      "brand": {
          "brand_name": "SDA"
      },
      "order_date": "2018-01-25",
      "shipment_date": "2018-01-26"
  }
  </code></pre>
  
  <p>\data structure after applying to_representation() and PATCH works with modified update() fine but not POST and PUT does not.</p>
  
  <pre><code>    {
          "id": 1033,
          "order_date": "2018-01-25",
          "shipment_date": "2018-01-26",
          "client_name": "BAC",
          "brand_name": "SDA"
      }
  </code></pre>
  
  <p>However, I can't seem to implement properly the to_internal_value() method so that I can have a writable-nested-serializer using the new representation. Below is the error I get despite customizing the create() method and POSTING with the required data.</p>
  
  <p>\POST data</p>
  
  <pre><code>{
      "order_date": "2017-10-26",
      "shipment_date": "2017-11-11",
      "client_name": "ABC",
      "brand_name": "DEF"
  }
  </code></pre>
  
  <p>\Error message</p>
  
  <pre><code>{
      "client": [
          "This field is required."
      ],
      "brand": [
          "This field is required."
      ]
  }
  </code></pre>
  
  <p>Below is my code. The update() method works properly when using PATCH. But POST and PUT doesn't work so I'm thinking I'm missing some code linking the create() and to_internal_value() methods properly. Any help would be much appreciated.</p>
  
  <p>/serializers.py </p>
  
  <pre><code>class OrderSerializer(serializers.ModelSerializer):
      client = ClientSerializer()
      brand = BrandSerializer()
  
      class Meta:
          model = Order
          fields = ('id', 'client', 'brand', 'order_date',
                    'shipment_date',)
  
      def to_representation(self, obj):
          representation = super().to_representation(obj)
          client_representation = representation.pop('client')
          brand_representation = representation.pop('brand')
          for key in client_representation:
              representation[key] = client_representation[key]
          for key in brand_representation:
              representation[key] = brand_representation[key]
          return representation
  
      def to_internal_value(self, data):
          client_internal = {}
          brand_internal = {}
          for key in ClientSerializer.Meta.fields:
              if key in data:
                  client_internal[key] = data.pop(key)
          for key in BrandSerializer.Meta.fields:
              if key in data:
                  brand_internal[key] = data.pop(key)
          internal = super(OrderSerializer, self).to_internal_value(data)
          internal['client'] = client_internal
          internal['brand'] = brand_internal
  
          return internal
  
      def create(self, validated_data):
          client_data = validated_data.pop('client')
          brand_data = validated_data.pop('brand')
          client, created = Client.objects.get_or_create(
              client_name=client_data['client_name'])
          brand, created = Brand.objects.get_or_create(
              brand_name=brand_data['brand_name'])
          order = Order.objects.create(
              client=client, brand=brand, **validated_data)
          return order
  
      def update(self, instance, validated_data):
          client_data = validated_data.pop('client')
          brand_data = validated_data.pop('brand')
          client, created = Client.objects.get_or_create(
              client_name=client_data['client_name'])
          brand, created = Brand.objects.get_or_create(
              brand_name=brand_data['brand_name'])
          instance.brand = brand
          instance.client = client
          instance.order_date = validated_data['order_date']
          instance.shipment_date = validated_data['shipment_date']
          instance.save()
          return instance
  </code></pre>