Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#1579 closed defect (fixed)

Exclude in limit_choices_to doesn't work

Reported by: Rudolph Owned by: adrian
Component: Core (Other) Version: magic-removal
Severity: major Keywords: limit_choices_to exclude
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 (0)

Change History (4)

comment:1 Changed 8 years ago 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.

comment:2 Changed 8 years ago 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.

comment:3 Changed 8 years ago by lukeplant

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:4 Changed 8 years ago by adrian

  • milestone Version 0.92 deleted

Milestone Version 0.92 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.