Flattens an object for indexing. This loads a template (``search/indexes/{app_label}/{model_name}_{field_name}.txt``) and returns the result of rendering that template. ``object`` will be in its context.
(self, obj)
| 185 | return current_objects |
| 186 | |
| 187 | def prepare_template(self, obj): |
| 188 | """ |
| 189 | Flattens an object for indexing. |
| 190 | |
| 191 | This loads a template |
| 192 | (``search/indexes/{app_label}/{model_name}_{field_name}.txt``) and |
| 193 | returns the result of rendering that template. ``object`` will be in |
| 194 | its context. |
| 195 | """ |
| 196 | if self.instance_name is None and self.template_name is None: |
| 197 | raise SearchFieldError( |
| 198 | "This field requires either its instance_name variable to be populated or an explicit template_name in order to load the correct template." |
| 199 | ) |
| 200 | |
| 201 | if self.template_name is not None: |
| 202 | template_names = self.template_name |
| 203 | |
| 204 | if not isinstance(template_names, (list, tuple)): |
| 205 | template_names = [template_names] |
| 206 | else: |
| 207 | app_label, model_name = get_model_ct_tuple(obj) |
| 208 | template_names = [ |
| 209 | "search/indexes/%s/%s_%s.txt" |
| 210 | % (app_label, model_name, self.instance_name) |
| 211 | ] |
| 212 | |
| 213 | t = loader.select_template(template_names) |
| 214 | return t.render({"object": obj}) |
| 215 | |
| 216 | def convert(self, value): |
| 217 | """ |
no test coverage detected