djangopython-2.7

'ProductList' object has no attribute 'object_list'


In my ProductList classs, when I try to call get_context_data in another method, I get an error 'ProductList' object has no attribute 'object_list'

def get_context_data(self, **kwargs):
        c = super(ProductList, self).get_context_data(**kwargs)
        c['category'] = self.category
        c['category_menu'] = self.get_category_menu()
        c['filters'] = self.filters
        c['expanded_filters'] = self.get_expanded_filters()
        c['active_filters'] = self.get_active_filters()
        c['category_list'] = self.category.get_children().filter(in_lists=True)
        c['colors_list'] = self.get_colors_list(c['object_list'])
        return c

def get_queryset(self):

    data = self.get_context_data()

What's causing this error?

How can I get object_list in my second method?


Solution

  • Sorry for such a blurred question. It's just my first try of Django. I read some documentation and realized that I can actually get a list of objects I need with the filter():

    data = self.model.objects.filter(categories__in=self.get_category_menu())