Django

Code

Ticket #1579 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

Exclude in limit_choices_to doesn't work

Reported by: Rudolph Assigned to: adrian
Milestone: Component: Core framework
Version: magic-removal Keywords: limit_choices_to exclude
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

I'm migrating my project to Magic Removal. I couldn't find how to do the equivalent of the old limit_choices_to = {'name__ne' : 'John'} in Magic Removal. This should be something like: limit_choices_to = {'name__exclude': 'John'} . See the discussion at Google group django-users.

Attachments

Change History

05/01/06 08:12:02 changed by lukeplant

Proposal: Change the implementation of limit_choices_to (and all places that accept a dictionary and pass it to .filter()) to accept a 'Q' object as an alternative. 'Q; objects can be detected by having the 'get_sql_clause' method (I believe it is currently '_get_sql_clause', but this doesn't make much sense -- it should be changed to be a public method instead of a semi-private one, since it is only ever used by external classes I think).

If it is a 'Q' object, then it is passed as a single positional parameter to filter(), instead of as keyword arguments. For the above use case, you can then do limit_choices_to = QNot(name='John') (IIRC). Since you can combine 'Q' objects, you can build up any arbitrary query this way, including queries that require custom 'Q'-type classes.

What do the other devs think? I'm happy to implement it.

05/05/06 18:32:31 changed by lukeplant

I misremembered about _get_sql_clause (that's actually a method on QuerySets?). Anyway, I'm working on this now, Adrian has given the go-ahead.

05/05/06 19:26:30 changed by lukeplant

  • status changed from new to closed.
  • resolution set to fixed.

(In [2850]) Fixed #1579 - added support for 'Q' objects in limit_choices_to.

10/24/06 15:17:23 changed by adrian

  • milestone deleted.

Milestone Version 0.92 deleted


Add/Change #1579 (Exclude in limit_choices_to doesn't work)




Change Properties
Action