1
我试图找出为什么这个工程:评论和content_object
>>> comments = Comment.objects.all()
>>>[c.content_object for c in comments]
[返回注释附加到对象的列表]
但这并不:
>>> c = Comment.objects.filter(id=111)
>>> c
[<Comment: Related object name here ...>]
>>> c.content_object
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'QuerySet' object has no attribute 'content_object'
在这两种情况下,每个“c”都是一个Comment实例。那么为什么c在第一种情况下有一个content_object属性,但在第二种情况下却没有?谢谢。
完全正确的丹尼尔。不知道我错过了什么(这是迟到:),但谢谢。 – shacker 2010-08-16 18:22:49