DjangoBlog icon indicating copy to clipboard operation
DjangoBlog copied to clipboard

Category define error

Open jzplyy opened this issue 1 year ago • 0 comments

this class method define categorys.append(child) is error?

 def get_sub_categorys(self):
        """
        获得当前分类目录所有子集
        :return:
        """
        categorys = []
        all_categorys = Category.objects.all()

        def parse(category):
            if category not in categorys:
                categorys.append(category)
            childs = all_categorys.filter(parent_category=category)
            for child in childs:
                if category not in categorys:
                    categorys.append(child)
                parse(child)

        parse(self)
        return categorys

jzplyy avatar Dec 19 '23 06:12 jzplyy