我正试图让所有类别的孩子:
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()
Run Code Online (Sandbox Code Playgroud)
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()
Run Code Online (Sandbox Code Playgroud)
现在我收到这个错误:"get()返回多个类别 - 它返回7!查找参数是{}"
谢谢
你的问题不在于MPTT.问题是它category是一个查询集,而不是一个实例 - get_children()是一个模型方法,而不是一个查询集方法.
用get而不是filter.
| 归档时间: |
|
| 查看次数: |
3705 次 |
| 最近记录: |