title: Django RestFramework group by
body: <p>My issue is related to Django RestFramework  and is about how to group elements.</p>
  <p>This is my <strong>serializers.py</strong></p>
  <pre><code>from collaborativeAPP.models import *
  from rest_framework import serializers
  
  class VocabSerializer(serializers.ModelSerializer):
      term_word = serializers.CharField(source='term.word',read_only=True)
      kwdGroup = serializers.StringRelatedField()
      class Meta:
          model = Vocab
          fields = ('id','term_word', 'meaning','kwdGroup')
  
  class TermSerializer(serializers.ModelSerializer):
      word = serializers.CharField(read_only=True)
      class Meta:
          model = Term
          fields = ('url', 'word')
  </code></pre>
  <p>The following json it's the actual result:</p>
  <pre><code>{&quot;results&quot;:[
              {
                  &quot;id&quot;: 5,
                  &quot;term_word&quot;: &quot;word1&quot;,
                  &quot;meaning&quot;: &quot;Text1&quot;
                  &quot;kwdGroup&quot;: &quot;A&quot;
              },
              {
                  &quot;id&quot;: 6,
                  &quot;term_word&quot;: &quot;word2&quot;,
                  &quot;meaning&quot;: &quot;Text2&quot;
                  &quot;kwdGroup&quot;: &quot;A&quot;
              },
              {
                  &quot;id&quot;: 7,
                  &quot;term_word&quot;: &quot;word3&quot;,
                  &quot;meaning&quot;: &quot;Text3&quot;
                  &quot;kwdGroup&quot;: &quot;A&quot;
              }
          ]}
  </code></pre>
  <p>As you can notice &quot;kwdGroup&quot; is a repetitive element that i which to group.</p>
  <p>I would like to group by kwdGroup</p>
  <pre><code>{&quot;A&quot;:[
         {
          &quot;id&quot;: 5,
          &quot;term_word&quot;: &quot;word1&quot;,
          &quot;meaning&quot;: &quot;Text1&quot;
          },
          {
          &quot;id&quot;: 6,
          &quot;term_word&quot;: &quot;word2&quot;,
          &quot;meaning&quot;: &quot;Text2&quot;
          },
          {
          &quot;id&quot;: 7,
          &quot;term_word&quot;: &quot;word3&quot;,
          &quot;meaning&quot;: &quot;Text3&quot;
          }
      ]
  }
  </code></pre>
  <p>I'm looking for answers on <a href="http://www.django-rest-framework.org/" rel="nofollow noreferrer">http://www.django-rest-framework.org/</a> on api guide but i'm having difficulties to find an approach to lead with it.
  Do you share this same issue? Do you have any suggestion how can i do this? Do you have any example that deals with element grouping using Django RestFramework?</p>
  <p>Thanks in advance.</p>