Django Autocomplete Light限制查询结果

时间:2022-01-03 02:11:38

When I register autocomplete_light.AutocompleteModelBase and use it in my form, the results that are shown are always limited to 20. I can't find any option in the docs to increase the number of results that gets displayed on the form.

当我注册autocomplete_light.AutocompleteModelBase并在我的表单中使用它时,显示的结果总是限制为20.我在文档中找不到任何选项来增加在表单上显示的结果数。

autocomplete_light_regisrty.py

autocomplete_light_regisrty.py

class IssueAutocomplete(autocomplete_light.AutocompleteModelBase):
    model = Issue
    search_fields = ('^issue_number',)

autocomplete_light.register(
    IssueAutocomplete,
    attrs={
        'placeholder': 'Type an issue number...',
        'data-autocomplete-minimum-characters': 1
    },
)

forms.py

forms.py

class StoryForm(autocomplete_light.ModelForm):
    class Meta:
        model = Story
        fields = ('slug', 'summary', 'author', 'editor', 'issue',)

But when I search my form, only a maximum of 20 results appear, even though I have well over 60. This is replicated when I go to /autocomplete/IssueAutocomplete. Only 20 results appear at a time.

但是当我搜索我的表单时,即使我已经超过60,也只会出现最多20个结果。当我转到/ autocomplete / IssueAutocomplete时会复制。一次只能显示20个结果。

How do I get a full list of resuls?

如何获得完整的结果列表?

2 个解决方案

#1


5  

You should to use limit_choices as is described in documentation.

您应该使用文档中描述的limit_choices。

#2


4  

By default AutocompleteModelBase has the attribute named limit_choices which by default is set tot 20. You can overwrite it with a new value to expand it. Although not documented, if you want no limit pass -1 as the attribute is only to slice the results

默认情况下,AutocompleteModelBase具有名为limit_choices的属性,默认情况下将其设置为20.您可以使用新值覆盖它以展开它。虽然没有记录,但如果您不希望限制传递-1,因为该属性仅用于对结果进行切片

#1


5  

You should to use limit_choices as is described in documentation.

您应该使用文档中描述的limit_choices。

#2


4  

By default AutocompleteModelBase has the attribute named limit_choices which by default is set tot 20. You can overwrite it with a new value to expand it. Although not documented, if you want no limit pass -1 as the attribute is only to slice the results

默认情况下,AutocompleteModelBase具有名为limit_choices的属性,默认情况下将其设置为20.您可以使用新值覆盖它以展开它。虽然没有记录,但如果您不希望限制传递-1,因为该属性仅用于对结果进行切片