title: Django Rest Framework: Dynamically return subset of fields
body: <h2>Problem</h2>
  <p>As recommended in the blogpost <a href="http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#limiting-fields" rel="noreferrer">Best Practices for Designing a Pragmatic RESTful API</a>, I would like to add a <code>fields</code> query parameter to a Django Rest Framework based API which enables the user to select only a subset of fields per resource.</p>
  <h2>Example</h2>
  <p>Serializer:</p>
  <pre><code>class IdentitySerializer(serializers.HyperlinkedModelSerializer):
      class Meta:
          model = models.Identity
          fields = ('id', 'url', 'type', 'data')
  </code></pre>
  <p>A regular query would return all fields.</p>
  <p><code>GET /identities/</code></p>
  <pre><code>[
    {
      &quot;id&quot;: 1,
      &quot;url&quot;: &quot;http://localhost:8000/api/identities/1/&quot;,
      &quot;type&quot;: 5,
      &quot;data&quot;: &quot;John Doe&quot;
    },
    ...
  ]
  </code></pre>
  <p>A query with the <code>fields</code> parameter should only return a subset of the fields:</p>
  <p><code>GET /identities/?fields=id,data</code></p>
  <pre><code>[
    {
      &quot;id&quot;: 1,
      &quot;data&quot;: &quot;John Doe&quot;
    },
    ...
  ]
  </code></pre>
  <p>A query with invalid fields should either ignore the invalid fields or throw a client error.</p>
  <h2>Goal</h2>
  <p>Is this possible out of the box somehow? If not, what's the simplest way to implement this? Is there a 3rd party package around that does this already?</p>