Simplifying id__exact lookups

44 views
Skip to first unread message

Jacob Kaplan-Moss

unread,
Jul 22, 2005, 5:18:48 PM7/22/05
to django-d...@googlegroups.com
Howdy folks --

We had quite the lively talk on IRC this afternoon about the
verbosity of "id__exact" lookups. A few people mentioned that it's
pretty annoying to have to type a comparatively long string for the
most common lookup type.

We talked about a few other options -- you can see the whole
discussion at http://loglibrary.com/show_page/view/179?
Multiplier=3600&Interval=6&StartTime=1122065878 -- but in the end
came up with a fairly simple proposal:

Let "mod.get_object(pk=something)" be the same as "mod.get_object
(id__exact=something)" -- where "id" would obviously get replaced by
the actual name of the primary key (should it be different).

What about it?

Jacob

Jeremy Dunck

unread,
Jul 22, 2005, 5:44:45 PM7/22/05
to django-d...@googlegroups.com
On 7/22/05, Jacob Kaplan-Moss <ja...@jacobian.org> wrote:

> Let "mod.get_object(pk=something)" be the same as "mod.get_object
> (id__exact=something)" -- where "id" would obviously get replaced by
> the actual name of the primary key (should it be different).

And anyone that has a column named "id" which is not actually the PK
deserves the pain they'll feel. ;-)

Robin Munn

unread,
Jul 22, 2005, 5:50:22 PM7/22/05
to django-d...@googlegroups.com
On 7/22/05, Jacob Kaplan-Moss <ja...@jacobian.org> wrote:
> Let "mod.get_object(pk=something)" be the same as "mod.get_object
> (id__exact=something)" -- where "id" would obviously get replaced by
> the actual name of the primary key (should it be different).
>
> What about it?

Since I came up with the idea, I'm obviously +1. :-)

Seriously, though, this would solve most of the annoyance I feel at
having to type "id__exact" all the time. Plus it has the added bonus
of being much shorter to type if your primary key is named
CustomerSocialSecurityNumber. :-) It doesn't solve every case where a
shorthand for "field__exact" might be desired, but most often when
you're looking up on a non-pk field, you're expecting multiple
results, so you probably *want* that explicit __exact in there.

--
Robin Munn
Robin...@gmail.com
GPG key 0xD6497014

Ian Bicking

unread,
Jul 22, 2005, 7:55:18 PM7/22/05
to django-d...@googlegroups.com
Jacob Kaplan-Moss wrote:
> Let "mod.get_object(pk=something)" be the same as "mod.get_object
> (id__exact=something)" -- where "id" would obviously get replaced by
> the actual name of the primary key (should it be different).

Why not mod.get_object(something)?

--
Ian Bicking / ia...@colorstudy.com / http://blog.ianbicking.org

Robin Munn

unread,
Jul 22, 2005, 11:35:07 PM7/22/05
to django-d...@googlegroups.com
On 7/22/05, Ian Bicking <ia...@colorstudy.com> wrote:
>
> Jacob Kaplan-Moss wrote:
> > Let "mod.get_object(pk=something)" be the same as "mod.get_object
> > (id__exact=something)" -- where "id" would obviously get replaced by
> > the actual name of the primary key (should it be different).
>
> Why not mod.get_object(something)?

Everything else is handled by kwargs in the _parse_lookup() function;
I don't think primary-key lookups are special enough to break the
rules. Not when typing just three characters extra lets you stay
within the existing pattern.

BTW, this feature, once implemented, should allow us to close
http://code.djangoproject.com/ticket/168.

Robin Munn

unread,
Jul 23, 2005, 12:09:31 AM7/23/05
to django-d...@googlegroups.com
I've written a patch for the pk=(value) syntax and placed it on
http://code.djangoproject.com/ticket/163.
Reply all
Reply to author
Forward
0 new messages