Admin interface using CharField as a primary key

2 views
Skip to first unread message

Daniel Bimschas

unread,
Mar 30, 2006, 7:08:45 AM3/30/06
to django...@googlegroups.com
Hi there!

I'm currently trying to convert an old webapp written in PHP into a
django-based app. The PHP-System used VARCHAR-Fields as primary keys
in the MySQL - DB.

Now, if i convert the data for the new tables created by Django, I
have the problem that the admin interface can't edit any entries where
the title contains colons (":"), because the admin interface uses the
primary keys in the url created.

I'm currently using Django 0.92.

I really need some help here, or a bugfix or sth. I've put quite a lot
of work into this now :(


Regards, Daniel

Andy Dustman

unread,
Mar 30, 2006, 10:55:54 AM3/30/06
to django...@googlegroups.com
On 3/30/06, Daniel Bimschas <bims...@googlemail.com> wrote:
>
> Hi there!
>
> I'm currently trying to convert an old webapp written in PHP into a
> django-based app. The PHP-System used VARCHAR-Fields as primary keys
> in the MySQL - DB.
>
> Now, if i convert the data for the new tables created by Django, I
> have the problem that the admin interface can't edit any entries where
> the title contains colons (":"), because the admin interface uses the
> primary keys in the url created.
>
> I'm currently using Django 0.92.

What sort of field (i.e. models.XXXField) are you using for your
primary key? Sounds like maybe a SlugField? Unless you are using the
default primary key (implicit id = models.AutoField(), which is
INTEGER AUTO_INCREMENT)? You might then need to set primary_key in
Meta to prevent the default PK from being created. See the model-api
docs.

(All this assumes you are using the magic-removal branch, because you
did say 0.92.)

--
The Pythonic Principle: Python works the way it does
because if it didn't, it wouldn't be Python.

Daniel Bimschas

unread,
Mar 30, 2006, 12:16:24 PM3/30/06
to django...@googlegroups.com
If have a model like this:

class Article(meta.Model):
cite_key = meta.CharField(maxlength=255, primary_key=True)
...

where "cite_key" is a unique string used in a bibtex-file. The problem
now are the links to the edit pages created by the admin interface.
The html-code is for example:

<a href="AAMG:05/">

which should link to
"http://host/bibtexapp/admin/bib/articles/AAMG:05/" but the browser
interpretes this as "aamg:05/" because of the colons in the url. So
the thing would be to url-encode the key I think.

I was using 0.91 before, but switched to the trunk now.

2006/3/30, Andy Dustman <farc...@gmail.com>:

Daniel Bimschas

unread,
Mar 30, 2006, 12:17:51 PM3/30/06
to django...@googlegroups.com
Forgot: In the trunk the problem also exists.


2006/3/30, Daniel Bimschas <bims...@googlemail.com>:

Reply all
Reply to author
Forward
0 new messages