Related Field got invalid lookup: istartswith

Issue #82 new
Former user created an issue

Anytime I use django-datatables-view with ForeignKeys, and I try to search, it brings up the following error.

django.core.exceptions.FieldError: Related Field got invalid lookup: istartswith

I have tried following the following link which is for django-rest-framework-datatables, but it doesn't work also.

https://github.com/izimobil/django-rest-framework-datatables/issues/58

Comments (3)

  1. talesmm14

    To solve this problem I changed the following function.

    from django.db.models import Q, ForeignObject
    
    
    class ExempleListGrid(BaseDatatableView):
        model = Modelo
        columns = ['id', 'descricao', 'fabricante', 'ativo']
        order_columns = ['id', 'descricao', 'fabricante', 'ativo']
    
        def filter_queryset(self, qs):
            ...
                    if search and col["searchable"]:
                        if not isinstance(qs.model._meta.get_field(column), ForeignObject):
                            q |= Q(**{"{0}__{1}".format(column, filter_method): search})
            ...
    

    I tried to make a pull request, but I couldn't get authorization to create the branch... I didn't really understand this bitbucket.

  2. Emmanuel Nollase

    i think hopefully this is still relaevant what works for me

    columns = ['first_name', 'last_name', 'email', 'company.name', 'id']

    the foreign key is company and company.name

  3. Log in to comment