简体   繁体   English

用于在Django Admin中呈现外键的可扩展小部件

[英]Scalable Widget for Rendering Foreign Keys in Django Admin

Is there a widget for rendering a foreign key field in Django admin that can scale to handle an arbitrarily large table and provide a user-friendly interface for looking up a FK? 在Django admin中是否存在用于呈现外键字段的小部件,该小部件可以缩放以处理任意大的表并提供用于查找FK的用户友好界面?

The default widget in Django 1.3 is a select box that lists every record in the referenced table. Django 1.3中的默认小部件是一个选择框,其中列出了引用表中的每条记录。 For tables containing hundreds of thousands of records...this basically crashes the server. 对于包含成千上万条记录的表...这基本上会使服务器崩溃。 I see there's a ref_id_fields ModelAdmin option, for rendering the field as a simple text box, but that strikes me as a pretty un-user-friendly workaround since it expects the user to know the exact ID for the record they want to reference. 我看到有一个ref_id_fields ModelAdmin选项,用于将字段呈现为一个简单的文本框,但这令我震惊,因为它希望用户知道他们要引用的记录的确切ID,因此这是一种非常不友好的解决方法。

I'm surprised no solution for this is already builtin, but Googling only found me one project implementing a jQuery-powered autocomplete widget. 令我感到惊讶的是,目前还没有内置解决方案,但是Googling只发现我一个项目实现了jQuery驱动的自动完成小部件。 Are there any other solutions for this problem? 还有其他解决方案吗?

are you getting all the static files? 您是否正在获取所有静态文件? raw_id_fields come with an ajax widget, which puts a little magnifying glass next to the text box with the input widget. raw_id_fields带有一个ajax小部件,该小部件在带有输入小部件的文本框旁边放了一个小放大镜。 clicking brings up a popup with a changelist (including eg search) that you can use to find the id. 单击将弹出一个带有更改列表的弹出窗口(包括搜索),您可以使用该列表查找ID。 (and automatically insert by clicking the entry) (并通过单击条目自动插入)

see screenshot (first google image search) 查看屏幕截图 (首次Google图片搜索)

Django还有更多自动完成的应用程序: http : //djangopackages.com/grids/g/auto-complete/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM