我试图根据 url 中的 kwarg 过滤查询集。我的网址是这样的:
http://localhost:8000/notification/all/?type="workflow"
我想过滤url中是否存在type参数
class NotificationList(generics.ListAPIView):
model = Notification
serializer_class = NotificationSerializer
def get_queryset(self):
queryset = Notification.objects.filter(created_for=self.request.user)[:int(settings.NOTIFICATION_PAGE_SIZE)]
type_param = self.request.query_params.get('type')
last = self.request.query_params.get('last')
print("TYPE PARAm", type_param)
if str(type_param)=="workflow":
print("TRUEEEEEEEEEEEEEeeeee")
queryset = Notification.objects.filter(created_for=self.request.user).instance_of(WorkflowNotification)
if last:
last_notification_created_on = Notification.objects.get(id=last)
queryset = queryset.filter(created_on__lt=last_notification_created_on)
return queryset
目前,即使我将 url 中的类型指定为“工作流程”,它也没有进入 if 条件。可能出了什么问题?