How to exclude in limit_choices_to (magic removal)

242 views
Skip to first unread message

Rudolph

unread,
Apr 2, 2006, 5:24:01 AM4/2/06
to Django users
Hi,

I'm migrating my project to Magic Removal. I couldn't find how to do
the equivalent of the limit_choices_to = {'name__ne' : 'John'} in Magic
Removal.

Rudolph

tonemcd

unread,
Apr 2, 2006, 10:39:00 AM4/2/06
to Django users
I tried __ne and (somewhat naively) __exclude and neither works.

The Wiki documentation at
http://code.djangoproject.com/wiki/RemovingTheMagic#Changedtemplatenamesingenericviews
says that 'ne is no longer a valid lookup type'

I had a look around and in the MR version of the file
db/backends/mysql/base.py we have this;

OPERATOR_MAPPING = {
'exact': '= %s',
'iexact': 'LIKE %s',
'contains': 'LIKE BINARY %s',
'icontains': 'LIKE %s',
'gt': '> %s',
'gte': '>= %s',
'lt': '< %s',
'lte': '<= %s',
'startswith': 'LIKE BINARY %s',
'endswith': 'LIKE BINARY %s',
'istartswith': 'LIKE %s',
'iendswith': 'LIKE %s',
}

Whereas in the 0.91 release (at the location core/db/backends/mysql.py)
we have this;

OPERATOR_MAPPING = {
'exact': '= %s',
'iexact': 'LIKE %s',
'contains': 'LIKE BINARY %s',
'icontains': 'LIKE %s',
'ne': '!= %s',
'gt': '> %s',
'gte': '>= %s',
'lt': '< %s',
'lte': '<= %s',
'startswith': 'LIKE BINARY %s',
'endswith': 'LIKE BINARY %s',
'istartswith': 'LIKE %s',
'iendswith': 'LIKE %s',
}

I guess you could add the line into your own MR installation, but there
might be some side-effects (I did it as a test and got repeated entries
- I've since edited it out)

Anyone know the proper way of doing this?

Cheers,
Tone

Jacob Kaplan-Moss

unread,
Apr 2, 2006, 11:53:33 AM4/2/06
to django...@googlegroups.com
Hey folks --

Magic-removal replaced the "__ne" and friends with the much-clearer
"exclude()" lookup filter::

People.objects.exclude(firstname="Jacob")

Is the same as trunk's::

people.get_list(name__ne="Jacob")

Jacob

Rudolph

unread,
Apr 2, 2006, 11:58:11 AM4/2/06
to Django users
Hi,

I noticed the cleaner syntax (really nice!), but I wonder how this
applies to "limit_choices_to".

Rudolph

tonemcd

unread,
Apr 2, 2006, 12:45:01 PM4/2/06
to Django users
Same here Jacob - can you shed some light on this please? - ;)

(ie __exclude doesn't work)

Cheers,
Tone

Rudolph

unread,
Apr 3, 2006, 4:11:02 PM4/3/06
to Django users
Is this worth a bug report? Seems like a bug ...

Rudolph

Joseph Kocherhans

unread,
Apr 3, 2006, 4:26:09 PM4/3/06
to django...@googlegroups.com
On 4/3/06, Rudolph <rudolph...@gmail.com> wrote:
>
> Is this worth a bug report? Seems like a bug ...
>

Yeah. Please file a ticket. This is a bug.

Joseph

Rudolph

unread,
Apr 3, 2006, 5:16:42 PM4/3/06
to Django users
Ticket filed:
http://code.djangoproject.com/ticket/1579

I'm afraid I can't patch this myself (yet), so I'll just be patient.

Rudolph

Reply all
Reply to author
Forward
0 new messages