2014-07-06 2 views
0

django-filter 사용 날짜순 정렬 및 정렬을 설정할 수 있습니다.django-filter를 사용하여 정렬 할 때 null 날짜를 무시하는 방법

하지만 nullable 날짜순으로 정렬하려면 null 항목이 항상 목록의 맨 아래에 있도록하고 싶습니다. 이것을 제어하거나 무시할 수있는 방법이 있습니까?

# following ensures no projects are at bottom of list 
    if self.request.GET.get('o', None) == "-most_recent_project": 
     queryset = queryset.extra(select={ 
      'most_recent_project_date_is_not_null': 'most_recent_project IS NOT NULL', 
     }, 
            order_by=['most_recent_project_date_is_not_null', 'most_recent_project'], 
     ) 

그러나보기가 작동하지 않는다면 django_filters가이를 무시한다고 생각합니다.

답변

1

이 같은 것을 사용할 수 있습니다 : 잘 내 질문에 대답하지 않습니다 https://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships

+0

을하지만, 기본적으로 내가하지 않았다 아무것도 있지만 문제를 해결 :

if self.request.GET.get('o') == '-most_recent_project': queryset = queryset.filter(most_recent_project__isnull=False) ... 

당신은 여기에 대해 읽을 수 있습니다 이미 알아. 고맙습니다. – Kerridge0

+0

나는 문제 해결을 생각했다. – shalakhin

+0

예, 계속 진행하겠습니다. upvoted. – Kerridge0

관련 문제