【问题标题】:ascending=True not working in django-mptt升序=真在 django-mptt 中不起作用
【发布时间】:2021-06-17 08:54:22
【问题描述】:

您好,我目前正在关注 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'

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

【问题讨论】:

  • See 获取有关如何发布 MRE 的说明
  • 如果您觉得这个答案有用,请考虑接受它

标签: django django-mptt django-packages


【解决方案1】:

你用错了方法

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多