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.
Source code in nautobot/extras/querysets.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
annotate_config_context_data()
¶
Attach the subquery annotation to the base queryset.
Order By clause in Subquery is not guaranteed to be respected within the aggregated JSON array, which is why we include "weight" and "name" into the result so that we can sort it within Python to ensure correctness.
TODO This method does not accurately reflect location inheritance because of the reasons stated in _get_config_context_filters() Do not use this method by itself, use get_config_context() method directly on ConfigContextModel instead.