Enumerating objects in foreign key in the admin

17 views
Skip to first unread message

Christophe Pettus

unread,
May 31, 2014, 1:18:02 AM5/31/14
to django...@googlegroups.com
Right now, when one has a foreign key field in a detail page in the admin, it appears to enumerate the objects (one at a time) in order to build the pop-up. Obviously, if the other side of the foreign key relationship has a lot of entries, this can be a problem. Short of doing a different, custom widget, is there a way to avoid this?
--
-- Christophe Pettus
x...@thebuild.com

Russell Keith-Magee

unread,
May 31, 2014, 1:23:44 AM5/31/14
to Django Users
Hi Christophe,

The built-in way to handle this is to add a `raw_id_fields` declaration to your ModelAdmin or Inline definition. This will replace the pulldown select widget (populated with every possible value) with a single text input that stores the primary key of the related object, plus a popup that makes it easy (well… easier) to find the right PK.


Of course, a custom widget might give you a better UI, but if you're just looking to make it work and not drag the rendering of the admin UI page to a crawl, it works.

Yours,
Russ Magee %-)


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/DBC6EF68-4DE3-432B-9237-D3973D80825F%40thebuild.com.
For more options, visit https://groups.google.com/d/optout.

Christophe Pettus

unread,
May 31, 2014, 12:33:29 PM5/31/14
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages