3👍
✅
By using self here:
def get_queryset(self):
self.publisher = get_object_or_404(Publisher, name=self.kwargs['publisher'])
return Book.objects.filter(publisher=self.publisher)
We’re declaring a class level variable that can be used by other methods in this class. That means we can use the variable by calling:
self.publisher
Anywhere in the class.
Source:stackexchange.com