2👍
✅
Looking at your code:
def get_queryset(self):
sculpture_slug = get_object_or_404(Sculpture, slug__iexact=self.kwargs['slug'])
Here you’re fetching the Sculpture
object that matches the captured slug.
return Sculpture.objects.filter(slug=sculpture_slug)
And then you get the Sculpture
object whose slug is another Sculpture
object. I wonder how this even works in some cases 🙂
Since you have a DetailView
, you can directly use get_object()
:
class SculptureDetailView(DetailView):
def get_object(self):
return get_object_or_404(Sculpture, slug__iexact=self.kwargs['slug'])
Source:stackexchange.com