Coverage for netbox/models/lookups.py: 77%
26 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 18:35 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 18:35 +0000
1from django.db.models import Lookup
3__all__ = (
4 'Ancestor',
5 'AncestorOrEqual',
6 'Descendant',
7 'DescendantOrEqual',
8)
11class Ancestor(Lookup):
12 """
13 `path` is a strict ancestor of the queried path: path @> rhs AND path <> rhs.
15 Use `ancestor_or_equal` for the inclusive form (`@>`).
16 """
17 lookup_name = 'ancestor'
19 def as_sql(self, compiler, connection):
20 lhs, lhs_params = self.process_lhs(compiler, connection)
21 rhs, rhs_params = self.process_rhs(compiler, connection)
22 return f'({lhs} @> {rhs} AND {lhs} <> {rhs})', lhs_params + rhs_params + lhs_params + rhs_params
25class AncestorOrEqual(Lookup):
26 """`path` is an ancestor of (or equal to) the queried path: path @> rhs"""
27 lookup_name = 'ancestor_or_equal'
29 def as_sql(self, compiler, connection):
30 lhs, lhs_params = self.process_lhs(compiler, connection)
31 rhs, rhs_params = self.process_rhs(compiler, connection)
32 return f'{lhs} @> {rhs}', lhs_params + rhs_params
35class Descendant(Lookup):
36 """
37 `path` is a strict descendant of the queried path: path <@ rhs AND path <> rhs.
39 Use `descendant_or_equal` for the inclusive form (`<@`).
40 """
41 lookup_name = 'descendant'
43 def as_sql(self, compiler, connection):
44 lhs, lhs_params = self.process_lhs(compiler, connection)
45 rhs, rhs_params = self.process_rhs(compiler, connection)
46 return f'({lhs} <@ {rhs} AND {lhs} <> {rhs})', lhs_params + rhs_params + lhs_params + rhs_params
49class DescendantOrEqual(Lookup):
50 """`path` is a descendant of (or equal to) the queried path: path <@ rhs"""
51 lookup_name = 'descendant_or_equal'
53 def as_sql(self, compiler, connection):
54 lhs, lhs_params = self.process_lhs(compiler, connection)
55 rhs, rhs_params = self.process_rhs(compiler, connection)
56 return f'{lhs} <@ {rhs}', lhs_params + rhs_params