我有一个分类树,我想获取分类树中的所有产品。MPTT的文档表明,它只有可以调用来获取对象的方法。
我想知道如何才能使其与相关对象一起工作,例如,此语法将是理想的:
Product.objects.get(Q(category__ancestors=my_category)|Q(category=my_category))在django-mptt有这样的东西吗?
发布于 2012-03-22 15:42:30
尝试在产品查询集中嵌套get_descendants()查询集:
Product.objects.get(category__in=my_category.get_descendants(include_self=True))这应该与执行以下操作相同:
Product.objects.get(category__pk__in=my_category.get_descendants(include_self=True).values_list('pk'))https://stackoverflow.com/questions/9812305
复制相似问题