我知道這是一個認識問題,但聽我說,我目前在query_params
在我看來,這樣的篩選:鏈過濾器查詢參數
filter_date = self.request.query_params.get('filter_date', None)
if filter_date is not None:
queryset = queryset.filter(next_action_date__gte=filter_date)
return queryset
和我展示我的聯繫人通過next_action_date
,現在我有這樣的自定義數據結構,我需要將它添加到這個過濾器,它會顯示從最重要不重要我接觸,我試圖將其添加到過濾器,但我沒有得到任何數據,所以我怎麼能適當地完成這項工作,有人可以告訴我嗎?
這是我get_queryset:
def get_queryset(self):
queryset = LeadContact.objects.none()
user = self.request.user
if user.has_perm('cms_sales.can_view_full_lead_contact_list'):
queryset = LeadContact.objects.all()
elif user.has_perm('cms_sales.can_view_lead_contact'):
queryset = LeadContact.objects.filter(account_handler=user)
filter_date = self.request.query_params.get('filter_date', None)
# This is the custom ordering data structure
virgin_data = LeadContact.objects.filter(status=LeadContactConstants.STATUS_PRISTINE)
contacted_data = LeadContact.objects.filter(status=LeadContactConstants.STATUS_CONTACTED)
qualified_data = LeadContact.objects.filter(status=LeadContactConstants.STATUS_QUALIFIED)
client_data = LeadContact.objects.filter(status=LeadContactConstants.STATUS_CLIENT)
# This needs to be added to the filter so it will properly order
# contacts
order_data = list(client_data) + list(qualified_data) + list(contacted_data) + list(virgin_data)
if filter_date is not None:
queryset = queryset.filter(next_action_date__gte=filter_date)
return queryset
必須結果來查詢集?它可以排序,正常的對象列表嗎? –
@MateuszKnapczyk好,我需要的鞋我的聯繫人通過'next_action_date'並把它們正確排序,我很開放的建議,你能告訴我,你需要更多的數據? – PetarP