|
|
@@ -18,9 +18,22 @@ class Empty(Lookup):
|
|
|
return f"CAST(LENGTH({sql}) AS BOOLEAN) IS TRUE", params
|
|
|
|
|
|
|
|
|
+class NetHost(Lookup):
|
|
|
+ """
|
|
|
+ Similar to ipam.lookups.NetHost, but casts the field to INET.
|
|
|
+ """
|
|
|
+ lookup_name = 'net_host'
|
|
|
+
|
|
|
+ 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 'HOST(CAST(%s AS INET)) = HOST(%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
|
|
|
+ Similar to ipam.lookups.NetContainsOrEquals, but casts the field to INET.
|
|
|
"""
|
|
|
lookup_name = 'net_contains_or_equals'
|
|
|
|
|
|
@@ -32,4 +45,5 @@ class NetContainsOrEquals(Lookup):
|
|
|
|
|
|
|
|
|
CharField.register_lookup(Empty)
|
|
|
+CachedValueField.register_lookup(NetHost)
|
|
|
CachedValueField.register_lookup(NetContainsOrEquals)
|