title: Django DetailView - How to change the get_object to check a field
body: <p>So I want to make a <code>DetailView</code> that shows a photo by itself and its associated information. However, I want to have it make sure the user has permission to access the photo as well.</p>
  
  <p>This is the urls.py for the view</p>
  
  <pre><code>url(r'^photo/(?P&lt;slug&gt;[\-\d\w]+)/$', views.PhotoDetail.as_view(), name='photo'),
  </code></pre>
  
  <p>This is the views.py</p>
  
  <pre><code>class PhotoDetail(DetailView):
      template_name = 'otologue/photo_detail.html'
  
      def get_object(self, queryset=None):
          slug = self.get_slug_field()
          print(slug)
          object_instance = Photo.objects.filter(slug=slug)
          print(object_instance)
          object_user = object_instance.photoextended.user
          user = get_object_or_404(User, username=self.request.user)  # Get the user in the view
  
          if object_user != user:  # See if the object_user is the same as the user
              return HttpResponseForbidden('Permission Error')
  
          else:
              return object_instance
  </code></pre>
  
  <p>As you can see I try to <code>get_slug_field()</code> but when I print it it only says 'slug' when the slug should say the objects slug which is in the url.
  From this the object_instance doesn't have any object and then why I try to get the user from it, it can't find any data. </p>