title: Django REST Framework: adding additional field to ModelSerializer
body: <p>I want to serialize a model, but want to include an additional field that requires doing some database lookups on the model instance to be serialized:</p>
  <pre><code>class FooSerializer(serializers.ModelSerializer):
    my_field = ... # result of some database queries on the input Foo object
    class Meta:
          model = Foo
          fields = ('id', 'name', 'myfield')
  </code></pre>
  <p>What is the right way to do this? I see that <a href="http://www.django-rest-framework.org/api-guide/serializers/#including-extra-context" rel="noreferrer">you can pass in extra &quot;context&quot;</a> to the serializer, is the right answer to pass in the additional field in a context dictionary?</p>
  <p>With that approach, the logic of getting the field I need would not be self-contained with the serializer definition, which is ideal since every serialized instance will need <code>my_field</code>. Elsewhere in the DRF serializers documentation it <a href="http://django-rest-framework.org/api-guide/serializers.html#specifying-fields-explicitly" rel="noreferrer">says</a> &quot;extra fields can correspond to any property or callable on the model&quot;. Are &quot;extra fields&quot; what I'm talking about?</p>
  <p>Should I define a function in <code>Foo</code>'s model definition that returns <code>my_field</code> value, and in the serializer I hook up my_field to that callable? What does that look like?</p>
  <p>Happy to clarify the question if necessary.</p>