Code

Opened 5 years ago

Closed 3 years ago

Last modified 3 years ago

#10918 closed (fixed)

to_field and raw_id_fields popup in ModelAdmin

Reported by: dcramer Owned by: nobody
Component: contrib.admin Version: 1.1
Severity: Keywords: raw_id_field, to_field, lookup
Cc: CollinAnderson Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 CollinAnderson 4 years ago.
Git formated patch that fixes the problem.
10918_admin_search_missing_fk_to_field.diff (1.9 KB) - added by julien 3 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 5 years ago by dcramer

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 5 years ago by brosner

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 5 years ago by anonymous

  • 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 Changed 4 years ago by CollinAnderson

  • Needs tests set
  • Patch needs improvement set
  • Summary changed from to_field and raw_id_fields in ModelAdmin to to_field and raw_id_fields popup in ModelAdmin
  • Version changed from SVN to 1.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 Changed 4 years ago by CollinAnderson

  • Patch needs improvement unset

Changed 4 years ago by CollinAnderson

Git formated patch that fixes the problem.

comment:6 Changed 4 years ago by CollinAnderson

  • Cc CollinAnderson added

Changed 3 years ago by julien

comment:7 Changed 3 years ago by julien

  • Has patch set
  • milestone set to 1.3
  • Needs tests unset
  • Triage Stage changed from Accepted to Ready for checkin

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

comment:8 Changed 3 years ago by russellm

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

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 Changed 3 years ago by russellm

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 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 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.