2013-09-07 1 views
1

내가 뭘 하려는지 가장 가까운 article에는 관련이없는 article_history이없는 것을 찾으려고합니다. 여기아이들이없는 가장 오래된 객체 찾기 - Django

내가 뭘하려하지만, 작동하지 않는 : 나는 조건과 일치하는 모든 기사를 얻을 :이 뒤에

the_article = Article.objects.filter(cowcode=country).filter(pubdate__range=(start_date,end_date)).exclude(article_history_set__id > 0).order_by('pubdate')[0] 

내 생각이 제외 될 때까지 쿼리가 작동하는지이었다. article history이 아직없는 가장 빠른 기사를 찾으려면 exclude article_history ID가> 0 인 기사가있는 모든 기사가 작동해야합니다. 왜 안 그래?

누군가 나를 도와 줄 수 있다면 정말 좋을 것입니다.

답변

2

...end_date)).filter(article_history_set__isnull).order_by... 

또는

...end_date)).exclude(article_history_set__isnull=False).order_by… 
+0

굉장 시도, 감사합니다! – LukasKawerau

+0

'filter'가 아닌'exclude'와 함께 작동하는지 확인하십시오 –

+0

예, 단지 "= ​​False"를 추가해야하므로 다음과 같이 보입니다 : ')). exclude (article_history_set__isnull = False) .order_by ...' – LukasKawerau