djangordf.query

Q objects compose filter expressions with &, |, and ~. Pass them as positional arguments to RDFManager.filter alongside the usual kwargs.

Q objects for composing filter expressions with &, | and ~.

A Q instance carries a connector (AND or OR), a negation flag, and a list of children. Children are either other Q subtrees or (key, value) leaves built from kwargs at construction time. The operator dunders return new Q instances; same-connector chains are flattened so the resulting tree stays shallow.

class djangordf.query.Q(*args, _connector='AND', _negated=False, **kwargs)[source]

Bases: object

Composable filter expression for RDFManager.filter().

Parameters:
  • args (Union['Q', _Leaf])

  • _connector (str)

  • _negated (bool)

  • kwargs (object)

AND = 'AND'
OR = 'OR'
property is_leaf_only: bool

True when every child is a (key, value) leaf — useful for the byte-identical fast path in the flat filter case.

leaves()[source]

Iterate only the direct (key, value) leaves (not Q children). Used by the flat path.

Return type:

Iterable[Tuple[str, object]]

subtrees()[source]

Direct Q children (excluding leaves).

Return type:

Sequence[Q]