Django admin:将所选相关字段框更改为自动填充 [英] Django admin: Change selected box of related fields to autocomplete
问题描述
我们有一些使用户作为外键的型号。但是,在我们的系统中有大约25000个用户,找到我们需要的用户有点困难。
We have some models that are have a user as a foreign key. But with about 25000 users in our system, it's a bit daunting to find the one we need.
有没有一个解决方案比选择框更好?也许是一个自动完成,所以我们可以开始输入用户名/地址?还是只是一个搜索框?当切换这些对象的相关用户时,25000个未排序的用户越来越难。
Is there a solution out there that's better than the select box? Maybe an autocomplete so we can start typing the user name / address? Or just a search box? When switching the related user for these objects, it's getting harder and harder with 25000 unsorted users.
即使设置它以用户名排序用户也是有帮助的。 p>
Even just setting it to sort the users by username would be helpful.
推荐答案
我有这个问题,我的结论是使用自动填充字段。它在大多数情况下效果很好。唯一的问题是当你有大量的条目大致相同。例如,在您的情况下,如果您为该名称键入 Robert ,并且列表中有几百个Robert 条目...
I had this problem and my conclusion was to use an autocomplete field instead. It works pretty well in most cases. The only problem is when you have a lot of entries that are mostly the same. For example, in your case, if you type Robert for the name and there's a few hundred Robert entries in the list...
有许多应用程序向Django管理员添加自动填充:
There are many apps that add autocomplete to the Django admin:
- django-extensions ( ForeignKeyAutocompleteAdmin )
- django-autocomplete (在谷歌代码)
- django-ajax选择
- django-admin-autocomplete
- django-autocomplete ( tyrion)
- django-extensions (ForeignKeyAutocompleteAdmin)
- django-autocomplete (on google code)
- django-ajax-selects
- django-admin-autocomplete
- django-autocomplete (tyrion)
我最喜欢的是最后一个。它写得很好,可以和管理员一起使用,它可以与ManyToManyFields,ForeignKeyFields,CharFields等一起使用。
My preferred one is the last one. It's well written, it can be used with the admin and outside of the admin, it works with ManyToManyFields, ForeignKeyFields, CharFields, etc.
我做了一个 fork 为我的客户添加了一些喜欢的查找(放大镜)按钮,如 ForeignKeyRawIdWidget
。
I did a fork of this project for my client that adds some niceties like a lookup (loupe) button like the ForeignKeyRawIdWidget
.
这篇关于Django admin:将所选相关字段框更改为自动填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!