title: Create and redirect to slug urls in django
body: <p>I have doctor profiles on my app and would like to create slug urls for all of them. So I've the following questions</p>
  
  <ol>
  <li>How do I create slug urls for the new doctors and as well as existing doctors in the database?</li>
  </ol>
  
  <p>The url looks like this <code>http://localhost:8000/docprofile/6/</code></p>
  
  <p>and I want to make it like this <code>http://localhost:8000/doctor/james-smith/</code></p>
  
  <p>I want the slug to be based on the name of the doctor</p>
  
  <ol start="2">
  <li>How do I do a permanent url redirection after implementing slug urls such that if a person goes to <code>http://localhost:8000/docprofile/6/</code>, the page is redirected to <code>http://localhost:8000/doctor/james-smith/</code></li>
  </ol>
  
  <p>Here is the models.py</p>
  
  <pre><code>class Doctor(models.Model):
      name = models.CharField(max_length=1300)
      specialization = models.ForeignKey(Specialization)
  
      def __unicode__(self):
        return u"%s %s" % (self.name, self.specialization)
  
      def get_absolute_url(self):
          from django.core.urlresolvers import reverse
          return reverse('kk1.views.showDocProfile', args=[str(self.id)])
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>def showDocProfile(request, id):
      doctor = Doctor.objects.get(id=id)
      clinic = Clinic.objects.get(id=doctor.clinic.id)
  
      d = getVariables(request,dictionary={'page_name': doctor.name +" "+ doctor.specialization.name +" -})
  
  
      d.update({'doctor': doctor, 'clinic': clinic,'form': form })
      return render(request, 'kk1/docprofile.html', d)
  </code></pre>
  
  <p>urls.py</p>
  
  <pre><code>url(r'^docprofile/(?P&lt;id&gt;\d+)/$', views.showDocProfile, name='showDocProfile'),
  </code></pre>