Commit d609894b authored by Jamesie Pic's avatar Jamesie Pic
Browse files

Add autocomplete

parent f1c19341
Pipeline #152 passed with stages
in 18 seconds
...@@ -5,7 +5,10 @@ from django.contrib import admin ...@@ -5,7 +5,10 @@ from django.contrib import admin
from views.home import HomeView from views.home import HomeView
from views.dossier_ac import ProposalAutocomplete from views.autocomplete import (
ProposalAutocomplete,
RepresentativeAutocomplete,
)
from views.dossier_detail_base import DossierDetailBase from views.dossier_detail_base import DossierDetailBase
from views.dossier_detail_recommendations import DossierDetailRecommendations from views.dossier_detail_recommendations import DossierDetailRecommendations
from views.dossier_detail_proposals import DossierDetailProposals from views.dossier_detail_proposals import DossierDetailProposals
...@@ -119,13 +122,19 @@ urlpatterns = [ ...@@ -119,13 +122,19 @@ urlpatterns = [
name='dossier-documents' name='dossier-documents'
), ),
# Dossier autocomplete for admin # Autocomplete
url( url(
r'^autocomplete/proposal/$', r'^autocomplete/proposal/$',
ProposalAutocomplete.as_view(), ProposalAutocomplete.as_view(),
name='proposal-autocomplete', name='proposal-autocomplete',
), ),
url(
r'^autocomplete/representative/$',
RepresentativeAutocomplete.as_view(),
name='representative-autocomplete',
),
# Theme list # Theme list
......
...@@ -4,9 +4,22 @@ from dal import autocomplete ...@@ -4,9 +4,22 @@ from dal import autocomplete
from django.db.models import Q from django.db.models import Q
from representatives.models import Representative
from representatives_votes.models import Proposal from representatives_votes.models import Proposal
class RepresentativeAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
qs = Representative.objects.all()
if self.q:
qs = qs.filter(
Q(full_name__icontains=self.q)
)
return qs
class ProposalAutocomplete(autocomplete.Select2QuerySetView): class ProposalAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self): def get_queryset(self):
qs = Proposal.objects.all() qs = Proposal.objects.all()
......
from dal import autocomplete
from django import forms from django import forms
from django.contrib import admin from django.contrib import admin
...@@ -76,6 +78,11 @@ class ThemedPositionAdminForm(ThemedAdminForm): ...@@ -76,6 +78,11 @@ class ThemedPositionAdminForm(ThemedAdminForm):
model = Position model = Position
fields = ('representative', 'datetime', 'kind', 'title', 'score', fields = ('representative', 'datetime', 'kind', 'title', 'score',
'text', 'link', 'published', 'themes') 'text', 'link', 'published', 'themes')
widgets = {
'representative': autocomplete.ModelSelect2(
url='representative-autocomplete',
)
}
class ThemedDossierAdmin(DossierAdmin): class ThemedDossierAdmin(DossierAdmin):
......
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