本文介绍了"ProductList"对象没有属性"object_list"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 ProductList 类中,当我尝试用另一种方法调用 get_context_data 时,出现错误'ProductList'对象没有属性'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?

如何在第二种方法中获取 object_list ?

How can I get object_list in my second method?

推荐答案

对于这样一个模糊的问题,我们深表歉意.这只是我第一次尝试Django.我阅读了一些文档,并意识到实际上可以使用 filter():

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())

这篇关于"ProductList"对象没有属性"object_list"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 03:27