我正在努力让所有孩子成为一个类别:
def list_sub(self, category_name):
# this will return the parent if exists
category = Category.objects.filter(seo_title__exact = seo_title).filter(lang__exact = 'pt-PT').filter(level__exact = 1)
if category:
# but this doesn't work and in the documentation there are no examples
# of how to get it. See link about the method
sub_categories = category.get_children()
http://django-mptt.github.com/django-mptt/models.html#get-children
qc = Category.objects.filter(seo_title__exact = cat).filter(lang__exact = 'pt-PT').filter(level__exact = 1)
category = qc.get()
if category:
qsc = category.get_children()
sub_categories = qsc.get()
现在我收到这个错误:“get()返回多个类别 - 它返回7个!查找参数是{}”
感谢
答案 0 :(得分:6)
你的问题不在于MPTT。问题是category
是查询集,而不是实例 - get_children()
是模型方法,而不是查询集方法。
使用get
代替filter
。