Commit 1e3bf2c9 authored by James Pic's avatar James Pic

Merge pull request #17 from political-memory/dossier_autocomplete

Added dossier autocomplete view
parents 2e45c93a 546c0b97
......@@ -2,7 +2,20 @@ from dal import autocomplete
from django.db.models import Q
from models import Proposal
from models import Dossier, Proposal
class DossierAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
qs = Dossier.objects.all()
if self.q:
qs = qs.filter(
Q(title__icontains=self.q) |
Q(reference__icontains=self.q)
)
return qs
class ProposalAutocomplete(autocomplete.Select2QuerySetView):
......
......@@ -17,12 +17,20 @@ urlpatterns = [
]
if 'dal_select2' in settings.INSTALLED_APPS:
from autocompletes import ProposalAutocomplete # noqa
from autocompletes import ( # noqa
DossierAutocomplete,
ProposalAutocomplete,
)
urlpatterns.append(
urlpatterns += [
url(
'^autocomplete/dossier/$',
DossierAutocomplete.as_view(),
name='dossier-autocomplete',
),
url(
'^autocomplete/proposal/$',
ProposalAutocomplete.as_view(),
name='proposal-autocomplete',
),
)
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment