升序=真在 django-mptt 中不起作用

问题描述

嗨,美好的一天,我目前正在关注 Django-MPTT 文档,但我在使用升序 = True 时遇到了问题。这是我的代码

views.py

def show_genres(request):
    Try01 = Genre.objects.filter(name="Rock")

    context = {'genres': Genre.objects.all(),'sample_ancestor': Try01.get_ancestors(ascending=True,include_self=True)}
    return render(request,"sampletemp/startup.html",context)

当我使用 Ascending=True 时,会出现错误提示

Exception Value: get_queryset_ancestors() got an unexpected keyword argument 'ascending'

我该如何解决。提前致谢!

解决方法

你使用了错误的方法

models.get_ancestors 有一个 ascending 字段,请参阅 here

managers.TreeManager.get_queryset_ancestors 但是没有,如图所示here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...