big drop-down lists, raw_id_admin and custom primary key: a bug?

90 views
Skip to first unread message

Emanuele

unread,
Oct 3, 2005, 11:27:16 AM10/3/05
to Django users
Hi,
to avoid big drop-down lists in admin interface I'm using
"raw_id_admin=True" inside ForeignKey(), so I can enter
object IDs manually. But what happens if my related object has
a _non-numeric_ custom primary key?

In my case I've a string as a custom primary key and I'd like
to enter this string instead of a raw numeric ID (currently
not present). So if I specify "raw_id_admin=True" in my case
the admin interface becomes a bit inconsistent, avoiding me to
enter the primary key value because it's not numeric.

Is it possible to have a sort of "raw_pk_admin=True" option
to insert custom primary keys in admin interface (and not only
numeric stuff)?

Thanks in advance,

Emanuele

Adrian Holovaty

unread,
Oct 3, 2005, 12:00:54 PM10/3/05
to django...@googlegroups.com
On 10/3/05, Emanuele <emanuele...@gmail.com> wrote:
> to avoid big drop-down lists in admin interface I'm using
> "raw_id_admin=True" inside ForeignKey(), so I can enter
> object IDs manually. But what happens if my related object has
> a _non-numeric_ custom primary key?
> [...]
> Is it possible to have a sort of "raw_pk_admin=True" option
> to insert custom primary keys in admin interface (and not only
> numeric stuff)?

Hey Emanuele,

Ah, looks like raw_id_admin doesn't support non-integer primary keys.
Rather than adding a separate raw_pk_admin option, we should just fix
raw_id_admin to support non-integer keys.

I've filed a ticket at http://code.djangoproject.com/ticket/586 .
Thanks for the heads-up!

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org

Emanuele

unread,
Oct 3, 2005, 7:41:34 PM10/3/05
to Django users
Thanks for the quick answer!

Wouldn't it be nice (useful?) if just after inserting the pk value (in
case of "raw_id_admin=True" I mean) we could see aside the __repr__()
of the corresponding record? Just as a double check. Using manual
insertion of pk values is a good alternative when dealing with big
drop-down lists, but it is not as easy as selecting from a list of
meaningful names...
Some sort of javascript (forgive me, I don't know javascript) should do
that.

Django automatic admin interface + models is going to become my
favorite web RAD tool :)

Emanuele

Adrian Holovaty

unread,
Oct 3, 2005, 8:35:48 PM10/3/05
to django...@googlegroups.com
On 10/3/05, Emanuele <emanuele...@gmail.com> wrote:
> Wouldn't it be nice (useful?) if just after inserting the pk value (in
> case of "raw_id_admin=True" I mean) we could see aside the __repr__()
> of the corresponding record? Just as a double check. Using manual
> insertion of pk values is a good alternative when dealing with big
> drop-down lists, but it is not as easy as selecting from a list of
> meaningful names...

Oooh, that's a good idea. Django already displays the __repr__() of
the corresponding record on the *change* page, but it'd be nice to do
it automatically (via Ajax) right after the field is populated on the
add page (or changed on the change page).

Sounds like a fun evening project for me...

Jason Huggins

unread,
Oct 4, 2005, 3:34:39 PM10/4/05
to Django users
Adrian Holovaty wrote:
> Oooh, that's a good idea. Django already displays the __repr__() of
> the corresponding record on the *change* page, but it'd be nice to do
> it automatically (via Ajax) right after the field is populated on the
> add page (or changed on the change page).


Yup... I noticed this bug, too. This was on my "list of small bugs that
I need to fix and submit patches for". :-)

Don't forget also... if the pop up selector is used to select the code,
it should update the __repr__ *and* the code displayed in the form.
Right now, it updates the selected, but does update the __repr__ until
the page is saved... It's quite confusing.

-jason

Adrian Holovaty

unread,
Oct 5, 2005, 10:13:38 PM10/5/05
to django...@googlegroups.com
On 10/3/05, Emanuele <emanuele...@gmail.com> wrote:
> to avoid big drop-down lists in admin interface I'm using
> "raw_id_admin=True" inside ForeignKey(), so I can enter
> object IDs manually. But what happens if my related object has
> a _non-numeric_ custom primary key?

I've fixed this bug in revision 785. Thanks again for the report!

Emanuele

unread,
Oct 6, 2005, 5:06:32 AM10/6/05
to Django users
I'm sorry but after updating (revision 786) this simple example
still has the problem I reported:

class Poll(meta.Model):
question = meta.CharField(maxlength=200,primary_key=True)
def __repr__(self):
return self.question
class META:
admin = meta.Admin()
pass
pass

class Choice(meta.Model):
poll = meta.ForeignKey(Poll,raw_id_admin=True)
choice = meta.CharField(maxlength=200)
class META:
admin = meta.Admin()
pass
pass

In admin interface I insert a poll and then when trying to insert
a choice (so a poll pk) I get "Please correct the error below. Enter
a whole number." around poll entry.

I just did an 'svn update' and django has the usual soft link to
/usr/local/lib/python2.4/site-packages/ , so I think I'm running the
correct version. Did I miss something?

Anyway, thanks!

Emanuele

Adrian Holovaty

unread,
Oct 6, 2005, 10:44:43 AM10/6/05
to django...@googlegroups.com
On 10/6/05, Emanuele <emanuele...@gmail.com> wrote:
> I'm sorry but after updating (revision 786) this simple example
> still has the problem I reported:

Hey Emanuele,

Update your Django code to revision 790, and give it another shot!

Emanuele

unread,
Oct 6, 2005, 4:51:52 PM10/6/05
to Django users
YESS! It works perfectly!

Thank you very much, this solves an important problem in my
application.

Emanuele

Adrian Holovaty

unread,
Oct 6, 2005, 5:10:07 PM10/6/05
to django...@googlegroups.com
On 10/6/05, Emanuele <emanuele...@gmail.com> wrote:
Excellent! Thank *you* for using Django.

:-)
Reply all
Reply to author
Forward
0 new messages