This can currently be achieved with: qs.annotate(lowername=Lower("name")).filter(lowername__in=['text'])
You’re free to add “iin” to your projects, but I'm not sure it's valuable enough to add to Django. Some years ago, there was an idea to allow python expressions to generate ORM filters, that would allow your lookup to done without any extensions: https://github.com/django/django/pull/12041 . On Sat, Oct 29, 2022 at 6:22 AM Jeremy Nauta <jeremypna...@gmail.com> wrote: > Hi all, I'd like to propose a new django filter: *__iin*. As the name > implies, this filter finds results that match one of the given values, > ignoring case. In other words, this is a hybrid of *__in *and *__iexact*. > > It surprises me that there are filters for* > qs.filter(field__iexact='text')*, *qs.filter(field__icontains='text')*, > and *qs.filter(field__in=[**'text']**)*, yet there is no > *qs.filter(field__iin=[**'text']**)* filter. > > I've made a POC for this field in postgres and it seems quite > straightforward. I'd be happy to try porting into the Django codebase, but > first I wanted to see if there is interest and/or feedback! Please let me > know what you think. > > > > > > > > > > > > > > > > > > > > > > > > > > > *from django.db.models import Fieldfrom django.db.models.lookups import > In@Field.register_lookupclass IIn(In): """ Case-insensitive version > of `__in` filters. Adapted from `In` and `IExact` transformers. """ > lookup_name = 'iin' def process_lhs(self, *args, **kwargs): sql, > params = super().process_lhs(*args, **kwargs) sql = f'LOWER({sql})' > return sql, params def process_rhs(self, qn, connection): > rhs, params = super().process_rhs(qn, connection) params = > tuple(p.lower() for p in params) return rhs, params* > > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-developers+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/bf623b99-9032-4ada-9739-ef63f2982e6an%40googlegroups.com > <https://groups.google.com/d/msgid/django-developers/bf623b99-9032-4ada-9739-ef63f2982e6an%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM2cJ24-mHUAGsADxY9-%3DjR9e56NJ%2BpdAbbDQB33i-D93w%40mail.gmail.com.