Code

Opened 9 months ago

Closed 9 months ago

Last modified 9 months ago

#20865 closed Bug (fixed)

admin raw_id_fields does not call value in limit_choices_to

Reported by: CollinAnderson Owned by: nobody
Component: contrib.admin Version: 1.6-beta-1
Severity: Normal Keywords:
Cc: CollinAnderson Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The docs show that limit_choices_to works with callables:
https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.limit_choices_to

However, the raw_id_fields widget does not handle this correctly, and it generates a url like so:
/admin/auth/user/?last_login__lte=%3Cbuilt-in%20method%20today%20of%20type%20object%20at%200xb72cd440%3E

As far as I can tell, this has never worked correctly. I have a simple app that demonstrates the problem:
https://github.com/collinanderson/limit_choices_to/commit/8e30de93dea1908ae363b8556e3f89d36b031e79

Attachments (0)

Change History (6)

comment:1 Changed 9 months ago by CollinAnderson

  • Has patch set
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Version changed from master to 1.6-beta-1

I realize that we're discussing a new api for limit_choices_to, but in the meantime this should fix it:
https://github.com/django/django/pull/1442

comment:2 Changed 9 months ago by timo

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 9 months ago by CollinAnderson

  • Needs tests unset

pull request now has a test https://github.com/django/django/pull/1442

comment:4 Changed 9 months ago by loic84

  • Triage Stage changed from Accepted to Ready for checkin

Looks good to me.

comment:5 Changed 9 months ago by Tim Graham <timograham@…>

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

In d53e574676ba0809394017f1f3a5bc24512e5bed:

Fixed #20865 -- Fixed raw_id_fields to work with callable limit_choices_to.

comment:6 Changed 9 months ago by Tim Graham <timograham@…>

In e3e0cf8a0f75ae18bc401182bfbdea2c27bb0244:

[1.6.x] Fixed #20865 -- Fixed raw_id_fields to work with callable limit_choices_to.

Backport of d53e574676 from master

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.