Return three values: - a list of 3-tuples of (expression, (sql, params), alias) - a klass_info structure, - a dictionary of annotations The (sql, params) is what the expression will produce, and alias is the "AS alias" for the column (possibly None).
(self, with_col_aliases=False)
| 238 | cls.get_select_from_parent(ki) |
| 239 | |
| 240 | def get_select(self, with_col_aliases=False): |
| 241 | """ |
| 242 | Return three values: |
| 243 | - a list of 3-tuples of (expression, (sql, params), alias) |
| 244 | - a klass_info structure, |
| 245 | - a dictionary of annotations |
| 246 | |
| 247 | The (sql, params) is what the expression will produce, and alias is the |
| 248 | "AS alias" for the column (possibly None). |
| 249 | |
| 250 | The klass_info structure contains the following information: |
| 251 | - The base model of the query. |
| 252 | - Which columns for that model are present in the query (by |
| 253 | position of the select clause). |
| 254 | - related_klass_infos: [f, klass_info] to descent into |
| 255 | |
| 256 | The annotations is a dictionary of {'attname': column position} values. |
| 257 | """ |
| 258 | select = [] |
| 259 | klass_info = None |
| 260 | annotations = {} |
| 261 | assert not (self.query.select and self.query.default_cols) |
| 262 | select_mask = self.query.get_select_mask() |
| 263 | if self.query.default_cols: |
| 264 | cols = self.get_default_columns(select_mask) |
| 265 | else: |
| 266 | # self.query.select is a special case. These columns never go to |
| 267 | # any model. |
| 268 | cols = self.query.select |
| 269 | selected = [] |
| 270 | select_fields = None |
| 271 | if self.query.selected is None: |
| 272 | selected = [ |
| 273 | *( |
| 274 | (alias, RawSQL(*args)) |
| 275 | for alias, args in self.query.extra_select.items() |
| 276 | ), |
| 277 | *((None, col) for col in cols), |
| 278 | *self.query.annotation_select.items(), |
| 279 | ] |
| 280 | select_fields = list( |
| 281 | range( |
| 282 | len(self.query.extra_select), |
| 283 | len(self.query.extra_select) + len(cols), |
| 284 | ) |
| 285 | ) |
| 286 | else: |
| 287 | select_fields = [] |
| 288 | for index, (alias, expression) in enumerate(self.query.selected.items()): |
| 289 | # Reference to an annotation. |
| 290 | if isinstance(expression, str): |
| 291 | expression = self.query.annotations[expression] |
| 292 | # Reference to a column. |
| 293 | elif isinstance(expression, int): |
| 294 | select_fields.append(index) |
| 295 | expression = cols[expression] |
| 296 | # ColPairs cannot be aliased. |
| 297 | if isinstance(expression, ColPairs): |
no test coverage detected