nautobot.apps.querysets - Nautobot Documentation

Skip to content

# `nautobot.apps.querysets`

Nautobot QuerySet classes and utilities.

## `nautobot.apps.querysets.ConfigContextModelQuerySet`

Bases: `RestrictedQuerySet`

QuerySet manager used by models which support ConfigContext (device and virtual machine).

Includes a method which appends an annotation of aggregated config context JSON data objects. This is implemented as a subquery which performs all the joins necessary to filter relevant config context objects. This offers a substantial performance gain over ConfigContextQuerySet.get_for_object() when dealing with multiple objects.

This allows the annotation to be entirely optional.

### `annotate_config_context_data()`

Attach the subquery annotation to the base queryset.

Note that the underlying function of our JSONBAgg in MySQL, `JSONARRAY_AGG`, does not support an `ordering`, unlike PostgreSQL's implementation. This is why we include "weight" and "name" into the result so that we can sort it within Python to ensure correctness.

Do not use this method by itself, use get_config_context() method directly on ConfigContextModel instead.