1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Proof of concept for showing containing prefixes when searching for ip-addresses.

This commit is contained in:
kkthxbye-code
2023-02-06 14:00:34 +01:00
committed by Jeremy Stretch
parent 315371bf7c
commit ce166b12ce
3 changed files with 36 additions and 9 deletions

View File

@ -1,4 +1,4 @@
from django.db.models import CharField, Lookup
from django.db.models import CharField, TextField, Lookup
class Empty(Lookup):
@ -14,4 +14,17 @@ class Empty(Lookup):
return 'CAST(LENGTH(%s) AS BOOLEAN) != %s' % (lhs, rhs), params
class NetContainsOrEquals(Lookup):
"""
This lookup has the same functionality as the one from the ipam app except lhs is cast to inet
"""
lookup_name = 'net_contains_or_equals'
def as_sql(self, qn, connection):
lhs, lhs_params = self.process_lhs(qn, connection)
rhs, rhs_params = self.process_rhs(qn, connection)
params = lhs_params + rhs_params
return 'CAST(%s as inet) >>= %s' % (lhs, rhs), params
CharField.register_lookup(Empty)
TextField.register_lookup(NetContainsOrEquals)