Get the default QuerySet to index when doing an index update. Subclasses can override this method to take into account related model modification times. The default is to use ``SearchIndex.index_queryset`` and filter based on ``SearchIndex.get_updated_field
(self, using=None, start_date=None, end_date=None)
| 160 | return self.index_queryset(using=using) |
| 161 | |
| 162 | def build_queryset(self, using=None, start_date=None, end_date=None): |
| 163 | """ |
| 164 | Get the default QuerySet to index when doing an index update. |
| 165 | |
| 166 | Subclasses can override this method to take into account related |
| 167 | model modification times. |
| 168 | |
| 169 | The default is to use ``SearchIndex.index_queryset`` and filter |
| 170 | based on ``SearchIndex.get_updated_field`` |
| 171 | """ |
| 172 | extra_lookup_kwargs = {} |
| 173 | model = self.get_model() |
| 174 | updated_field = self.get_updated_field() |
| 175 | |
| 176 | update_field_msg = ( |
| 177 | "No updated date field found for '%s' " "- not restricting by age." |
| 178 | ) % model.__name__ |
| 179 | |
| 180 | if start_date: |
| 181 | if updated_field: |
| 182 | extra_lookup_kwargs["%s__gte" % updated_field] = start_date |
| 183 | else: |
| 184 | warnings.warn(update_field_msg) |
| 185 | |
| 186 | if end_date: |
| 187 | if updated_field: |
| 188 | extra_lookup_kwargs["%s__lte" % updated_field] = end_date |
| 189 | else: |
| 190 | warnings.warn(update_field_msg) |
| 191 | |
| 192 | index_qs = None |
| 193 | |
| 194 | if hasattr(self, "get_queryset"): |
| 195 | warnings.warn( |
| 196 | "'SearchIndex.get_queryset' was deprecated in Haystack v2." |
| 197 | " Please rename the method 'index_queryset'." |
| 198 | ) |
| 199 | index_qs = self.get_queryset() |
| 200 | else: |
| 201 | index_qs = self.index_queryset(using=using) |
| 202 | |
| 203 | if not hasattr(index_qs, "filter"): |
| 204 | raise ImproperlyConfigured( |
| 205 | "The '%r' class must return a 'QuerySet' in the 'index_queryset' method." |
| 206 | % self |
| 207 | ) |
| 208 | |
| 209 | # `.select_related()` seems like a good idea here but can fail on |
| 210 | # nullable `ForeignKey` as well as what seems like other cases. |
| 211 | return index_qs.filter(**extra_lookup_kwargs).order_by(model._meta.pk.name) |
| 212 | |
| 213 | def prepare(self, obj): |
| 214 | """ |
no test coverage detected