Draft: Ajoute get_queryset dans ModelSearch #774

Closed
bclement wants to merge 1 commit from bclement/autocomplete-queryset into master
3 changed files with 12 additions and 2 deletions

View file

@ -905,6 +905,9 @@ class ParticipantAutocomplete(Select2QuerySetView):
model = Participant
search_fields = ("user__username", "user__first_name", "user__last_name")
def get_queryset(self):
return super().get_queryset().select_related("user", "tirage")
participant_autocomplete = buro_required(ParticipantAutocomplete.as_view())

View file

@ -18,6 +18,9 @@ class KfetAccountSearch(autocomplete.ModelSearch):
]
verbose_name = _("Comptes existants")
def get_queryset(self):
return super().get_queryset().select_related("profile__account_kfet")
def get_queryset_filter(self, *args, **kwargs):
qset_filter = super().get_queryset_filter(*args, **kwargs)
qset_filter &= Q(profile__account_kfet__isnull=False)

View file

@ -98,7 +98,11 @@ class ModelSearch(SearchUnit):
def __init__(self):
if self.verbose_name is None:
self.verbose_name = "{} search".format(self.model._meta.verbose_name)
model = self.get_queryset().model
self.verbose_name = "{} search".format(model._meta.verbose_name)
def get_queryset(self):
return self.model.objects.all()
def get_queryset_filter(self, keywords):
filter_q = Q()
@ -122,7 +126,7 @@ class ModelSearch(SearchUnit):
of the search fields.
"""
return self.model.objects.filter(self.get_queryset_filter(keywords))
return self.get_queryset().filter(self.get_queryset_filter(keywords))
# ---