Compute the default columns for selecting every field in the base model. Will sometimes be called to pull in related models (e.g. via select_related), in which case "opts" and "start_alias" will be given to provide a starting point for the traversal. Return
(
self, select_mask, start_alias=None, opts=None, from_parent=None
)
| 981 | self.query.reset_refcounts(refcounts_before) |
| 982 | |
| 983 | def get_default_columns( |
| 984 | self, select_mask, start_alias=None, opts=None, from_parent=None |
| 985 | ): |
| 986 | """ |
| 987 | Compute the default columns for selecting every field in the base |
| 988 | model. Will sometimes be called to pull in related models (e.g. via |
| 989 | select_related), in which case "opts" and "start_alias" will be given |
| 990 | to provide a starting point for the traversal. |
| 991 | |
| 992 | Return a list of strings, quoted appropriately for use in SQL |
| 993 | directly, as well as a set of aliases used in the select statement (if |
| 994 | 'as_pairs' is True, return a list of (alias, col_name) pairs instead |
| 995 | of strings as the first component and None as the second component). |
| 996 | """ |
| 997 | result = [] |
| 998 | if opts is None: |
| 999 | if (opts := self.query.get_meta()) is None: |
| 1000 | return result |
| 1001 | start_alias = start_alias or self.query.get_initial_alias() |
| 1002 | # The 'seen_models' is used to optimize checking the needed parent |
| 1003 | # alias for a given field. This also includes None -> start_alias to |
| 1004 | # be used by local fields. |
| 1005 | seen_models = {None: start_alias} |
| 1006 | select_mask_fields = set(composite.unnest(select_mask)) |
| 1007 | |
| 1008 | for field in opts.concrete_fields: |
| 1009 | model = field.model._meta.concrete_model |
| 1010 | # A proxy model will have a different model and concrete_model. We |
| 1011 | # will assign None if the field belongs to this model. |
| 1012 | if model == opts.model: |
| 1013 | model = None |
| 1014 | if ( |
| 1015 | from_parent |
| 1016 | and model is not None |
| 1017 | and issubclass( |
| 1018 | from_parent._meta.concrete_model, model._meta.concrete_model |
| 1019 | ) |
| 1020 | ): |
| 1021 | # Avoid loading data for already loaded parents. |
| 1022 | # We end up here in the case select_related() resolution |
| 1023 | # proceeds from parent model to child model. In that case the |
| 1024 | # parent model data is already present in the SELECT clause, |
| 1025 | # and we want to avoid reloading the same data again. |
| 1026 | continue |
| 1027 | if select_mask and field not in select_mask_fields: |
| 1028 | continue |
| 1029 | alias = self.query.join_parent_model(opts, model, start_alias, seen_models) |
| 1030 | column = field.get_col(alias) |
| 1031 | result.append(column) |
| 1032 | return result |
| 1033 | |
| 1034 | def get_distinct(self): |
| 1035 | """ |
no test coverage detected