incorrect field type for object_pk in contrib.comments?

13 views
Skip to first unread message

smcoll

unread,
Sep 16, 2008, 3:42:46 PM9/16/08
to Django developers
Looking at contrib.comments admin, i noted that the Object ID input is
a textarea. i thought that was strange, since i expceted an input
(type="text"). Turns out, in the model, this is a TextField, rather
than a CharField. http://code.djangoproject.com/browser/django/trunk/django/contrib/comments/models.py#L23
Is there a reason this should be a TextField, or is that a mistake?

alex....@gmail.com

unread,
Sep 16, 2008, 5:31:16 PM9/16/08
to Django developers
It's intentional, usually you see an object_pk as an integer field,
however that means it won't work with any field with a custom primary
key, specifically those with string type pks. And a textfield offers
the flexibility to work with all of those.

On Sep 16, 3:42 pm, smcoll <smc...@gmail.com> wrote:
> Looking at contrib.comments admin, i noted that the Object ID input is
> a textarea.  i thought that was strange, since i expceted an input
> (type="text").  Turns out, in the model, this is a TextField, rather
> than a CharField.  http://code.djangoproject.com/browser/django/trunk/django/contrib/com...

Ludvig Ericson

unread,
Sep 19, 2008, 12:50:38 PM9/19/08
to django-d...@googlegroups.com
On Sep 16, 2008, at 23:31, alex....@gmail.com wrote:

>
> It's intentional, usually you see an object_pk as an integer field,
> however that means it won't work with any field with a custom primary
> key, specifically those with string type pks. And a textfield offers
> the flexibility to work with all of those.

I'm no DBA, but it doesn't take a rocket scientist to realize how
inefficient it'll become for large datasets.

I'd say the default should be an IntegerField, just like it is for
automatic primary keys, and then provide some mechanism for changing
in that 0.1% corner case where the PK isn't an integer.

Ludvig Ericson

alex....@gmail.com

unread,
Sep 19, 2008, 1:17:47 PM9/19/08
to Django developers
The issue is it's a generic foreign key, so to change it at that time,
would mean the comments app would have to go through every installed
app and just look to see if any had a CharField or other non-integer
PK and then set it to be that time, since the app can't know at table
creation which models will be commentable. I'd agree it's probably
not ideal, but I can't think of a better solution.

On Sep 19, 12:50 pm, Ludvig Ericson <ludvig.eric...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages