받은 편지함보기를 쓰고 있는데 본 메시지에서 보이지 않는 메시지를 제외하고 싶습니다. 내 코드는 다음과 같습니다쿼리 집합에서 쿼리 집합을 제외하는 가장 좋은 방법은 무엇입니까
데프 render_notifications (요청) : 당신은 내가 편리하지 않는 것 루프를 사용하여 모든 보이지 않는 메시지를 제외하고 아니에요 볼 수 있듯이
unseen_notices = notification.Notice.objects.filter(recipient=request.user,unseen=True).order_by("-added") notices = notification.Notice.objects.filter(recipient=request.user).exclude(id__in = [i.id for i in unseen_notices]).order_by("-added") for msg in unseen_notices: msg.unseen = False msg.save() context = RequestContext(request,{'notices':notices, 'unseen_notices':unseen_notices}) return render_to_response('my_notifications.html',context_instance=context)
물론이 라인은 성능 문제를 일으키는가?
: 그리고 마지막으로 내가 비슷한이 라인을 대체 할 수있는 방법이사항 = notification.Notice.objects.filter (받는 사람 = request.user) .exclude (id__in = unseen_messages)
편집 : 페이지를 방문 할 때와 같이 나는 모든 보이지 않는 메시지를 표시하기 때문에
나는 제대로 보이지 않는 = 거짓을 사용하여 볼 메시지를 얻을 수 없습니다. 이상한 이유로 알림 쿼리에서 unseen = False를 사용하면 표시되지 않은 모든 메시지가 notices 쿼리에서 검색됩니다.
궁금한 점이 있다면, '눈에 보이지 않는 = 거짓'으로 필터링 할 수 없습니까? 즉, 'notices = notification.Notice.objects.filter (receipient = request.user, unseen = False) ...' –
내가 그렇게하면 보이지 않는 메시지가 표시된 것으로 표시되고 이유는 알 수 없지만 보이지 않게됩니다. 고지 쿼리 집합. – iva123