[Django] #34402: Admin searchfields for inherited model

1 view
Skip to first unread message

Django

unread,
Mar 10, 2023, 11:10:23 AM3/10/23
to django-...@googlegroups.com
#34402: Admin searchfields for inherited model
------------------------------------------+------------------------
Reporter: Pavel Pančocha | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
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

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/34402>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 11, 2023, 10:06:38 AM3/11/23
to django-...@googlegroups.com
#34402: Admin searchfields for inherited model
--------------------------------+--------------------------------------

Reporter: Pavel Pančocha | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------

Comment (by Mariusz Felisiak):

Both cases `pk` and `id` works with the `__exact` lookup. Do you need
`__iexact`?

--
Ticket URL: <https://code.djangoproject.com/ticket/34402#comment:1>

Django

unread,
Mar 13, 2023, 8:11:11 AM3/13/23
to django-...@googlegroups.com
#34402: Admin searchfields for inherited model
--------------------------------+------------------------------------
Reporter: Pavel Pančocha | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* stage: Unreviewed => Accepted


Comment:

Agreed, this restriction should be documented of fixed.

--
Ticket URL: <https://code.djangoproject.com/ticket/34402#comment:2>

Reply all
Reply to author
Forward
0 new messages