0

I get custom lookup for filtering foreign key field from this answer.

from django.db.models import Lookup

class EfficientInLookup(Lookup):
    lookup_name = "ineff"

    def as_sql(self, compiler, connection):
        lhs, lhs_params = self.process_lhs(compiler, connection)
        rhs, rhs_params = self.process_rhs(compiler, connection)
        params = lhs_params + list(rhs_params)
        return "%s IN (SELECT unnest(ARRAY(%s)))" % (lhs, rhs), params

But I have an error in the string lhs, lhs_params = self.process_lhs(compiler, connection) when I am trying use it.

Using:

queryset = queryset.filter(child__id__ineff=[1,2,3]

Error:

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

How can I write a custom lookup for foreign key fields?

MikeS
  • 1,058
  • 1
  • 10
  • 19

0 Answers0