简体   繁体   中英

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?

The default widget in Django 1.3 is a select box that lists every record in the referenced table. 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.

I'm surprised no solution for this is already builtin, but Googling only found me one project implementing a jQuery-powered autocomplete widget. 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. clicking brings up a popup with a changelist (including eg search) that you can use to find the id. (and automatically insert by clicking the entry)

see screenshot (first google image search)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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