[Answered ]-After change class function doesn't work

2đź‘Ť

âś…

Your ContentDetailView class was inherited from DetailView, but your IndexView is inherited from ListView.

If you look at docs of List View you can see that there is no method named get_object(). As in the docs,

The List View render some list of objects, set by self.model or self.queryset.
self.queryset can actually be any iterable of items, not just a queryset.

So, the self.object you refer to in the view, doesn’t exist.

But in the case of Detail View, if you look at the docs,

The DetailView render a “detail” view of an object.

By default this is a model instance looked up from self.queryset, but the
view will support display of any object by overriding self.get_object().

The logic which you are implementing in your IndexView is clearly wrong.
You would need to look into the docs first.

👤zaidfazil

Leave a comment