U
U
Untiwe2021-02-15 22:49:46
Django
Untiwe, 2021-02-15 22:49:46

How to override child get_context_data from child ListView?

There is a class PostsList from ListView

class PostsList(ListView):

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        print('check_perent')
        return context


And there is a SearchView class from PostsList

class SearchView(PostsList):

  def get_context_data(self, **kwargs):
            context = super().get_context_data(self, **kwargs)
            print('check_child')
            return context


I see that in the PostsList class the get_context_data method works, but in the SearchView it doesn't. Moreover, there were no such problems with the get_queryset method, everything worked right away

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
Untiwe, 2021-02-16
@Untiwe

And so, a day later, I found a solution. The function was defined in another class function, not in the class itself. Because I had 8 spaces instead of 4

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question