jimfunk / django-postgresql-netfields

Proper INET and CIDR fields for Django running on PostgreSQL
BSD 3-Clause "New" or "Revised" License
154 stars 65 forks source link

Unsupported lookup 'net_overlaps' for CidrAddressField #106

Closed oza4h07 closed 4 years ago

oza4h07 commented 4 years ago

models.py:

class LAN(models.Model): network_address = CidrAddressField() objects = NetManager()

within shell_plus session: `

from ipaddress import IPv4Network LAN.objects.create(network_address=IPv4Network('192.168.2.0/24')) net2 = IPv4Network('192.168.2.64/26') LAN.objects.filter(network_address__net_overlaps=net2) ... django.core.exceptions.FieldError: Unsupported lookup 'net_overlaps' for CidrAddressField or join on the field not permitted. ` Django is 3.0.7 and django-netfields is 1.2.2.

Thoughts ?

jimfunk commented 4 years ago

I can't reproduce this using CidrTestModel from the test app:

>>> CidrTestModel.objects.create(field=IPv4Network('192.168.2.0/24'))
<CidrTestModel: CidrTestModel object (2)>
>>> net2 = IPv4Network('192.168.2.64/26')
>>> CidrTestModel.objects.filter(field__net_overlaps=IPv4Network('192.168.2.64/26'))
<QuerySet [<CidrTestModel: CidrTestModel object (2)>]>

This is with Django 3.0.7 and the master branch.

Can you provide a failing test or perhaps a small app that exhibits the problem?

oza4h07 commented 4 years ago

Thank you very much for looking at this !

Did you pick django-netfields master branch on purpose or would you expect the seame result with the 1.2.2 version I used ?

higherorderfunctor commented 4 years ago

Is netfields added to INSTALLED_APPS in the config loaded with shell_plus?

oza4h07 commented 4 years ago

@higherorderfunctor

netfields was missing from INSTALLED_APPS adding it to my settings.py file, allowed me to have this:

LAN.objects.filter(network_address__net_overlaps=net2) <QuerySet [, ]> ` I feel a bit stupid to miss this as it was explicitly mentioned in project's Getting started instructions.

I think this can be marked as SOLVED

And thank you very much for your help

higherorderfunctor commented 4 years ago

@oza4h07, good to hear it is working. Based on the error, it sounded like the lookup function wasn't registering. It can happen to any of us.

oza4h07 commented 4 years ago

Thanks again