0
我有一個「Dialog」的經理看起來像這樣:Django:註釋後合併查詢集的問題
class AnnotationManager(models.Manager):
def get_query_set(self):
return super(AnnotationManager, self).get_query_set().annotate(
num_votes=Count('vote', distinct=True),
num_comments=Count('comment', distinct=True),
num_commentators = Count('comment__user', distinct=True),
)
投票和評論有一個ForeignKey to Dialog。註釋有一個ForeignKey用戶。當我這樣做:
dialogs_queryset = Dialog.public.filter(organization=organization)
dialogs_popularity = dialogs_queryset.exclude(num_comments=0) | dialogs_queryset.exclude(num_votes=0)
... dialogs_popularity將永遠不會返回組合,但只返回超過0條評論的對話框,或者如果我更改OR的順序,則對話框的評分超過0!
對我來說,預期的行爲是獲得超過0票的對話框和超過0條評論的對話框。
我錯過了什麼?或者註釋行爲中是否存在錯誤?
它看起來已經顛倒了你的代碼塊及其描述。 – 2010-03-10 01:23:19
我在每個代碼塊的描述中增加了更多內容。請再看一看,並更詳細地說明如何反轉描述。謝謝。 – istruble 2010-03-10 04:22:08
謝謝。爲了澄清我正在尋找具有選票,評論或兩者的對話。我試過你的代碼,但它仍然不起作用。 dialogs_queryset.filter(num_comments__ne = 0,num_votes__ne = 0) ...給我沒有投票和沒有評論的對話框。 dialogs_queryset.exclude(num_comments = 0,num_votes = 0) ...給我帶有評論和投票的對話。 代碼的行爲並不像我期望的那樣,當我對註釋值執行此操作時! – 2010-03-12 14:46:23