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