Hello all,
I’ve been using django.contrib.postgres.fields.ArrayField in a project and wanted to perform a case-insensitive exact lookup on any of the elements of the array field. Is this something that would be worth adding? I’d be happy to work on a ticket/PR.
Example:
class Biscuit(models.Model):
name = models.CharField(max_length=80)
ingredients = ArrayField(base_field=models.CharField(max_length=80))
def __str__(self):
return self.name
>>> Biscuit.objects.create(name="Bourbon", ingredients=["Cocoa", "Butter"])
>>> Biscuit.objects.create(name="Breakaway", ingredients=["Cocoa-solids", "Flour"])
Current functionality:
>>> Biscuit.objects.filter(ingredients__icontains=["cocoa"])
<Queryset []>
>>> Biscuit.objects.filter(ingredients__icontains="cocoa")
<Queryset [<Biscuit: Breakaway>, <Biscuit: Bourbon>]>
>>> Biscuit.objects.filter(ingredients__contains=["Cocoa"])
<Queryset [<Biscuit: Bourbon>]>
Desired functionality:
>>> Biscuit.objects.filter(ingredients__icontains=["cocoa"])
<Queryset [<Biscuit: Bourbon>]>
Thanks
Mark