ReverseManyToOneDescriptor对象没有属性order_by django 2.1 [英] ReverseManyToOneDescriptor object has no attribute order_by django 2.1

查看:56
本文介绍了ReverseManyToOneDescriptor对象没有属性order_by django 2.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从书中学习了python崩溃课程,我正在尝试为主题创建id,这是代码:

im learning from the book the python crash course and i'm trying to create ids for topic here's the code:

def topic(request, topic_id):
    """show a single topic and all its entries."""
    topic = Topic.objects.get(id=topic_id)
    entries = Topic.entry_set.order_by('-date_added')
    context = {'topic': topic, 'entries': entries}
    return render(request, 'learning_logs/topic.html', context)

当我转到 http://localhost:8000/topics/1/

推荐答案

您使用了模型类而不是实例.替换:

You used the model class instead of the instance. Replace:

entries = Topic.entry_set.order_by('-date_added')

作者

entries = topic.entry_set.order_by('-date_added') # lowercase "t"

这篇关于ReverseManyToOneDescriptor对象没有属性order_by django 2.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆