Skip to content

Commit

Permalink
Fix elasticsearch search backend tests broken by #5208
Browse files Browse the repository at this point in the history
  • Loading branch information
ababic committed Jun 17, 2019
1 parent 98d3ef4 commit 73e07ba
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
12 changes: 1 addition & 11 deletions wagtail/contrib/modeladmin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,19 +439,9 @@ def get_ordering(self, request, queryset):
# database backends.
pk_name = self.opts.pk.name

if hasattr(self.model, 'get_filterable_search_fields'):
# The model is indexed, so let's be careful to only add
# indexed fields to ordering where possible
filterable_fields = self.model.get_filterable_search_fields()
else:
filterable_fields = None

if not (set(ordering) & {'pk', '-pk', pk_name, '-' + pk_name}):
# ordering isn't already being applied to pk
if filterable_fields is None or 'pk' in filterable_fields:
ordering.append('-pk')
else:
ordering.append('-' + pk_name)
ordering.append('-' + pk_name)

return ordering

Expand Down
2 changes: 1 addition & 1 deletion wagtail/tests/modeladmintest/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Book(models.Model, index.Indexed):
search_fields = [
index.SearchField('title'),
index.FilterField('title'),
index.FilterField('pk'),
index.FilterField('id'),
]

def __str__(self):
Expand Down

0 comments on commit 73e07ba

Please sign in to comment.