'ProductList' object has no attribute 'object_list'

后端 未结 2 1965
陌清茗
陌清茗 2021-01-12 21:34

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

相关标签:
2条回答
  • 2021-01-12 22:24

    You might be getting the error on following line in get_context_data() of the super class:

    queryset = kwargs.pop('object_list', self.object_list)
    

    The get method of BaseListView sets the object_list on the view by calling the get_queryset method:

    self.object_list = self.get_queryset()
    

    But, in your case, you are calling get_context_data() in get_queryset method itself and at that time object_list is not set on the view.

    0 讨论(0)
  • 2021-01-12 22:31

    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())
    
    0 讨论(0)
提交回复
热议问题