Django管理:更改相关领域的选择框,自动完成 [英] Django admin: Change selected box of related fields to autocomplete

查看:204
本文介绍了Django管理:更改相关领域的选择框,自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一些型号正在有一个用户作为外键。但在我们的系统约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.

即使只是将它设置为通过用户名用户进行排序将是有益的。

Even just setting it to sort the users by username would be helpful.

推荐答案

我有这个问题,我的结论是使用自动完成场来代替。它的工作原理pretty以及在大多数情况下。唯一的问题是,当你有很多是大致相同的条目。例如,你的情况,如果你键入罗伯特的的名称,有一个几百的罗伯特的列表中的条目...

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 (on google code)
  • django-ajax-selects
  • django-admin-autocomplete
  • django-autocomplete (tyrion)

我preferred一个是最后一个。它写得很好,它可以与管理员和管理员外使用,它的工作原理与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.

我做这个项目为我的客户的,增加了一些细微像查找(放大镜)按钮像 ForeignKeyRawIdWidget

I did a fork of this project for my client that adds some niceties like a lookup (loupe) button like the ForeignKeyRawIdWidget.

这篇关于Django管理:更改相关领域的选择框,自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆