﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34402	Admin search_fields crashes for inherited model and __iexact lookup.	Pavel Pančocha	Ahmed Nassar	"Hello everyone!

Let's have model `Payer` and we will create `ExtendedPayer` from it
{{{
class ExtendedPayer(Payer):
    ...
}}}

We create admin for `ExtendedPayer` and define search fields. We want to be able to filter by `pk` of `Payer`. So I would expect these to work the same:


{{{
class ExtendedPayerAdmin(ModelAdmin):
    ...
    search_fields = (
        ""pk__iexact"", ...
    )
    ...
}}}

{{{
class ExtendedPayerAdmin(ModelAdmin):
    ...
    search_fields = (
        ""id__iexact"", ...
    )
    ...
}}}

Guess what? The ""id"" variant works ok and the ""pk"" fails with `Related Field got invalid lookup: iexact`

Why? Because in `construct_search` ([[https://github.com/django/django/blob/4b1bfea2846f66f504265cec46ee1fe94ee9c98b/django/contrib/admin/options.py#L1123|See Git]]) it's transformed to `pk__iexact__icontains` as it found out that the `pk` is `payer_ptr` which is FK. 

If we want to be correct, it should be `""payer_ptr__pk__iexact""`.

Please let me know if this behaviour is a bug or if is there any reason behind it."	Bug	assigned	contrib.admin	3.2	Normal			Sarah Boyce	Accepted	0	0	0	0	0	0
