I know it's a know subject but hear me out, I'm currently filter on query_params
in my view like this:
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
and I'm showing my contacts by next_action_date
, now I have this custom data structure and I need to add it to this filter so it will show my contacts from most important to unimportant, I've tried to add it to the filter but I'm not getting any data, so how can I appropriately get this done, can someone show me?
This is my 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