Arturo29
Arturo29

Reputation: 197

error: "int() argument must be a string, a bytes-like object or a number, not 'list'" in decorator @action

Good afternoon I am doing an @action decorator to a viewset in django rest to filter my model by a field and some values in an list ​​and thus obtain (properties) values ​​that will be consumed in the api rest.

My code is as follows:

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     
            )

and the error that returns me is the following:

int() argument must be a string, a bytes-like object or a number, not 'list'

How can i fix this?

Upvotes: 1

Views: 137

Answers (1)

ipaleka
ipaleka

Reputation: 3957

Try with setting the filter to a list:

queryset=Equipo.objects.filter(id_equipo__in=[106,107,156,157])

Btw, you should c/p your error in question.

Upvotes: 3

Related Questions