Recursive method that looks, for one or more objects, for an attribute that can be multiple objects (relations) deep.
(self, current_objects, attributes)
| 115 | return None |
| 116 | |
| 117 | def resolve_attributes_lookup(self, current_objects, attributes): |
| 118 | """ |
| 119 | Recursive method that looks, for one or more objects, for an attribute that can be multiple |
| 120 | objects (relations) deep. |
| 121 | """ |
| 122 | values = [] |
| 123 | |
| 124 | for current_object in current_objects: |
| 125 | if not hasattr(current_object, attributes[0]): |
| 126 | raise SearchFieldError( |
| 127 | "The model '%r' does not have a model_attr '%s'." |
| 128 | % (repr(current_object), attributes[0]) |
| 129 | ) |
| 130 | |
| 131 | if len(attributes) > 1: |
| 132 | current_objects_in_attr = self.get_iterable_objects( |
| 133 | getattr(current_object, attributes[0]) |
| 134 | ) |
| 135 | values.extend( |
| 136 | self.resolve_attributes_lookup( |
| 137 | current_objects_in_attr, attributes[1:] |
| 138 | ) |
| 139 | ) |
| 140 | continue |
| 141 | |
| 142 | current_object = getattr(current_object, attributes[0]) |
| 143 | |
| 144 | if current_object is None: |
| 145 | if self.has_default(): |
| 146 | current_object = self._default |
| 147 | elif self.null: |
| 148 | current_object = None |
| 149 | else: |
| 150 | raise SearchFieldError( |
| 151 | "The model '%s' combined with model_attr '%s' returned None, but doesn't allow " |
| 152 | "a default or null value." |
| 153 | % (repr(current_object), self.model_attr) |
| 154 | ) |
| 155 | |
| 156 | if callable(current_object): |
| 157 | values.append(current_object()) |
| 158 | else: |
| 159 | values.append(current_object) |
| 160 | |
| 161 | return values |
| 162 | |
| 163 | def split_model_attr_lookups(self): |
| 164 | """Returns list of nested attributes for looking through the relation.""" |