错误:装饰器@action中的int参数必须是字符串,类似字节的对象或数字,而不是'list'”>

问题描述 投票:0回答:1

下午好,我正在对Django rest中的视图集执行@action装饰器,以通过字段和列表中的一些值过滤我的模型,从而获得将在api rest中使用的(属性)值。

我的代码如下:

class EquiposViewSet(viewsets.ModelViewSet):

    queryset=Equipo.objects.all()
    serializer_class=EquipoSerializer

    @action(methods=['get'], detail=False, url_path='equipos-alarm', url_name='equipos_alarm')
    def equipos_alarm(self, request): # pylint: disable=invalid-name
            queryset=Equipo.objects.filter(id_equipo=[106,107,156,157])

            return Response ( {
                    'id_equipo':equipo.id_equipo,
                    'nombre_equipo':equipo.nombre,
                    'hora_ospf':equipo.recorrido_ospf,
                    'hora_speed':equipo.recorrido_speed,
                } 

                for equipo in queryset     
            )

返回我的错误如下:

int()参数必须是字符串,类似字节的对象或数字,而不是'list'

我该如何解决?

下午好,我正在对django rest中的视图集进行@action装饰,以通过字段和列表中的某些值过滤我的模型,从而获得将在...中使用的(属性)值。]

python django django-rest-framework
1个回答
0
投票

尝试将过滤器设置为列表:

queryset=Equipo.objects.filter(id_equipo__in=[106,107,156,157])
© www.soinside.com 2019 - 2024. All rights reserved.