Lookups for ArrayField + InetAddressField
Hello. Thank you for your efforts on this package. I have a question about using lookups when combining the inet Fields with an ArrayField.
Assume we have a model like this:
from django.db import models
from django.contrib.postgres.fields import ArrayField
from netfields import InetAddressField
class Foo(models.Model):
id = models.CharField(primary_key=True, unique=True, max_length=255)
networks = ArrayField(InetAddressField(), null=True, blank=True)
Foo.objects.create(id="test", networks=["1.1.1.1/24", "2.2.2.2/24"])
Is there any way we can apply the provided lookups like __net_contains_or_equals in this setup?
I am basically looking for a equivalent like this SQL query:
SELECT id FROM foo WHERE '1.1.1.55' <<= ANY (networks);
Any way to do this with the ORM?
As of right now the only way I can see is to use extra(where=...) as described at https://docs.djangoproject.com/en/5.1/ref/models/querysets/#extra
To add support in filter() we would need to register array variants of the 30 custom lookups to ArrayField, but we would have to be careful not to conflict existing lookups or ones that might be registered via other apps.
@jimfunk I appreciate the fast response. I didn't know about that extra method. That is sufficient for my use.