title: Outputting a different structure in Django REST Framework
body: <p>Let's say I have the following model:</p>
  
  <pre class="lang-py prettyprint-override"><code>class Attribute(models.Model):
      name = models.CharField(max_length=50)
      code = models.CharField(max_length=50)
      value = models.IntegerField(default=0)
  </code></pre>
  
  <p>How could I get a Django REST Framework serializer to render it as the following?</p>
  
  <pre><code>{
      attribute {
          'name' : 'shoes',
          'code': 'sho',
          'group': {
              'name' : 'shoes',
              'code': 'sho'
           }
      },
      value': 1
  }    
  </code></pre>
  
  <p><strong>Edit:</strong> My current serializer, which doesn't get it exactly correct:</p>
  
  <pre class="lang-py prettyprint-override"><code>from collections import namedtuple
  
  Group = namedtuple('Group', ('name code'))
  
  
  class GroupSerializer(serializers.Serializer):
      name = serializers.CharField(read_only=True)
      code = serializers.CharField(read_only=True)
  
  
  class AttributeSerializer(serializers.ModelSerializer):
      name = serializers.CharField()
      code = serializers.CharField()
      value = serializers.IntegerField()
      group = serializers.SerializerMethodField()
  
      class Meta:
          model = Attribute
          fields = ('name', 'code', 'value', 'group')
  
      def get_group(self, obj):
          serializer = GroupSerializer(
              Group(name=obj.name, code=obj.code),
          )
          return serializer.data
  </code></pre>