Error creating Django filter

Asked

Viewed 57 times

0

I am trying to create a filter but get error: Related Field got invalid lookup: icontains

msm if I use the related_name before the attribute n works.

class VersoesPublicadasList(generics.ListAPIView):
    """
        get:
        Retorna uma lista de todas as publicações
    """
    queryset = VersoesPublicadas.objects.all()
    serializer_class = VersoesPublicadasSerializer
    filter_backends = [SearchFilter]
    search_fields = ['publicacoes_empresas_pb_nome']

Someone’s been through it?

erro

  • 1

    Post the code from where you are applying the filter.

  • Posted the code snippet, @Augustoa

1 answer

0

According to the documentation of Django REST Framework, you must pass the parameters inside a tuple instead of a list, i.e.:

filter_backends = (SearchFilter,)
search_fields = ('publicacoes_empresas_pb_nome',)
  • I managed to solve.

  • filter_backends = [Djangofilterbackend] filter_fields = ['publicacoes___name', 'publicacoes__numero_versao', 'publicacoes__data_publicacao']

Browser other questions tagged

You are not signed in. Login or sign up in order to post.