title: How to add an url field to a serializer with Django Rest Framework
body: <p>I am following the tutorial on <a href="http://www.django-rest-framework.org/tutorial/3-class-based-views/" rel="noreferrer">Django Rest Framework - Tutorial 3 Class based views</a>. </p>
  
  <p><strong>How to add an url field (pointing to the current snippet) to a serializer?</strong></p>
  
  <p><strong>serializers.py</strong></p>
  
  <pre class="lang-python prettyprint-override"><code>from rest_framework import serializers
  from snippets.models import Snippet, LANGUAGE_CHOICES, STYLE_CHOICES
  from django.core.urlresolvers import reverse
  
  class SnippetSerializer(serializers.ModelSerializer):
  
      class Meta:
          model = Snippet
          fields = ('id', 'title', 'code', 'linenos', 'language', 'style')
  </code></pre>
  
  <p><strong>urls.py</strong> </p>
  
  <pre class="lang-python prettyprint-override"><code>urlpatterns = [
      url(r'^snippets/$', views.SnippetList.as_view()),
      url(r'^snippets/(?P&lt;pk&gt;[0-9]+)/$', views.SnippetDetail.as_view()),
  ]
  </code></pre>
  
  <p><strong>Actual output</strong></p>
  
  <pre class="lang-json prettyprint-override"><code>[  
     {  
        "id":1,
        "title":"",
        "code":"foo = \"bar\"\n",
        "linenos":false,
        "language":"python",
        "style":"friendly"
     }
  ]
  </code></pre>
  
  <p><strong>Desired output</strong>
  </p>
  
  <pre><code>[  
         {  
            "id":1,
            "url":"http://192.168.28.131:8000/snippets/1/",
            "title":"",
            "code":"foo = \"bar\"\n",
            "linenos":false,
            "language":"python",
            "style":"friendly"
         },
  
      ]
  </code></pre>