Search code examples
ajaxwidgetdjango-autocomplete-lightdjango-widgetdjango-widget-tweaks

How to change django-autocomplete-light number of loaded objs by default?


By default, the ajax behavior in autocomplete queries 10 first objs of the list and by scrolling you would see further next 10 results. But the scrolling doesn't work smoothly so I need to actually see all the result on the list by default. (it's loading 10 objs per scroll) Is there any option to change that or is there any way to manipulate the query to avoid chunked result?


Solution

  • paginate_by = XXX

    taking the same example as per the doc :

    class CountryAutocomplete(autocomplete.Select2QuerySetView):
        paginate_by = 20 
        def get_queryset(self):
            # Don't forget to filter out results depending on the visitor !
            if not self.request.user.is_authenticated():
                return Country.objects.none()
    
            qs = Country.objects.all()
    
            if self.q:
                qs = qs.filter(name__istartswith=self.q)
    
            return qs