Opened 16 years ago

Closed 14 years ago

Last modified 13 years ago

#10918 closed (fixed)

to_field and raw_id_fields popup in ModelAdmin

Reported by: David Cramer Owned by: nobody
Component: contrib.admin Version: 1.1
Severity: Keywords: raw_id_field, to_field, lookup
Cc: Collin Anderson 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

When using a to_field on a raw_id_field it fails under the following conditions:

1) Click the hourglass to find a foreign key.
2) Search (or filter)
3) Click the entry.

It inserts the primary key rather than the to_field.

However, if you do not search/filter it works just fine.

The problem seems to be with the fact that t=to_field is not passed on the search/filter.

Attachments (2)

to_field-10918.git.diff (1023 bytes ) - added by Collin Anderson 15 years ago.
Git formated patch that fixes the problem.
10918_admin_search_missing_fk_to_field.diff (1.9 KB ) - added by Julien Phalip 14 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 by David Cramer, 16 years ago

A quick fix (problem doesn't cover all bases) for us was to comment out the following two lines in main.py:

        # if TO_FIELD_VAR in self.params:
        #     del self.params[TO_FIELD_VAR]

comment:2 by Brian Rosner, 16 years ago

Triage Stage: UnreviewedAccepted

comment:3 by anonymous, 15 years ago

Keywords: raw_id_field to_field lookup added

I'm experiencing the same issue. The fix dcramer suggests does not work for me - it simply makes selecting the record take you to the add/edit record page as opposed to closing the popup and taking back a value.

comment:4 by Collin Anderson, 15 years ago

Needs tests: set
Patch needs improvement: set
Summary: to_field and raw_id_fields in ModelAdminto_field and raw_id_fields popup in ModelAdmin
Version: SVN1.1

I just ran into the same issue. The problem is that TO_FIELD_VAR needs to be removed from the query lookup_params, but not from the params used to construct new urls. I will attach a patch.

comment:5 by Collin Anderson, 15 years ago

Patch needs improvement: unset

by Collin Anderson, 15 years ago

Attachment: to_field-10918.git.diff added

Git formated patch that fixes the problem.

comment:6 by Collin Anderson, 15 years ago

Cc: Collin Anderson added

by Julien Phalip, 14 years ago

comment:7 by Julien Phalip, 14 years ago

Has patch: set
milestone: 1.3
Needs tests: unset
Triage Stage: AcceptedReady for checkin

Thanks Collin, the patch looks good. I've added a test.

comment:8 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: newclosed

In [15657]:

Fixed #10918 -- Ensure that the search widget on a raw_id_admin uses the right field name when the ForeignKey has a to_field definition. Thanks to David Cramer for the report, Collin Anderson for the fix, and Julien Phalip for the test.

comment:9 by Russell Keith-Magee, 14 years ago

In [15659]:

[1.2.X] Fixed #10918 -- Ensure that the search widget on a raw_id_admin uses the right field name when the ForeignKey has a to_field definition. Thanks to David Cramer for the report, Collin Anderson for the fix, and Julien Phalip for the test.

Backport of r15657 from trunk.

comment:10 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top