1
A
답변
1
해결책을 찾았습니다.
TAGLEN = TAGLIST.count()
withtags = PostTag.objects.filter(tagid__in=TAGLIST)
withall = withtags.values("postid").annotate(tagtotal=Count("tagid", distinct=True)).order_by()
withall.filter(tagtotal=TAGLEN).values_list("postid", flat=True)
이 모든 경우에 .query.__str__()
을 실행하면 기본적으로 아래의 SQL이 반환됩니다.
SELECT "postid"
FROM "posttags"
WHERE "tagid" IN (TAGLIST)
GROUP BY "postid"
HAVING COUNT(DISTINCT "tagid") = TAGLEN'
+0
개선 된 것이 있습니까? –
당신은 외래 키를 사용하지 않는, 그리고 BTW [이] (http://setthecode.pythonanywhere.com/post?id=19) 포스트 taginput에 좋은 이유 : –
'posttag.objects.get을 (tagid__icontains = you_list) .postid' 목록에 태그가 포함 된 포스트 태그의 게시물 ID를 반환합니다. –
@mohammedqudah : ** 모든 ** 태그를 포함해야합니다. –