Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions wagtailautocomplete/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def objects(request):
except Exception:
return HttpResponseBadRequest()

if getattr(queryset, 'live', None):
# autocomplete_allow_unpublished allows you to skip the live check and just return full queryset
allow_unpublished = getattr(model, 'autocomplete_allow_unpublished', False)
if getattr(queryset, 'live', None) and not allow_unpublished:
# Non-Page models like Snippets won't have a live/published status
# and thus should not be filtered with a call to `live`.
queryset = queryset.live()
Expand Down Expand Up @@ -68,7 +70,9 @@ def search(request):
filter_kwargs[field_name + '__icontains'] = search_query
queryset = model.objects.filter(**filter_kwargs)

if getattr(queryset, 'live', None):
# autocomplete_allow_unpublished allows you to skip the live check and just return full queryset
allow_unpublished = getattr(model, 'autocomplete_allow_unpublished', False)
if getattr(queryset, 'live', None) and not allow_unpublished:
# Non-Page models like Snippets won't have a live/published status
# and thus should not be filtered with a call to `live`.
queryset = queryset.live()
Expand Down