"""
Autocomplete registry for news articles
"""

# Django
from django.contrib.auth.models import User
from django.db.models.query import Prefetch

# Third Party
from autocomplete_light import shortcuts as autocomplete_light

# MuckRock
from muckrock.news.models import Article


class ArticleAutocomplete(autocomplete_light.AutocompleteModelTemplate):
    """Creates an autocomplete for picking articles"""
    choices = Article.objects.get_published().prefetch_related(
        Prefetch('authors', User.objects.select_related('profile'))
    )
    choice_template = 'autocomplete/article.html'
    search_fields = ['title']
    attrs = {
        'placeholder': 'Search for articles',
        'data-autocomplete-minimum-characters': 1
    }


autocomplete_light.register(Article, ArticleAutocomplete)

@@ -537,16 +537,27 @@
 ))%0A    )
+.distinct()
 %0A    cho
@@ -627,16 +627,30 @@
 %5B'title'
+, 'tags__name'
 %5D%0A    at

allow searching articles by tags in autocomplete close #1647