django / django/new-features

Include the fields being searched in the admin

Open
#129 3 comments 20 reactions 0 assignees View on GitHub
Admin
Dominant language
No language data
Stars
188
Forks
7
PR merge metrics
No merged PRs in 30d

Description

### Code of Conduct

- [x] I agree to follow Django's Code of Conduct

### Feature Description

When `ModelAdmin.search_fields` is set, the rendered search field should include the human readable version of those fields. This allows users to know what exactly is being searched.

### Problem

`search_fields` can be customized heavily, but the end user only knows about it if they have access to the code. This reduces how effectively a person can use the search field, because they don't know what exactly it will search.

At my past job, a person on the operations side of things pointed out to me that she never knew when she could search for a tenant’s name in the search bar versus using the dropdown (`list_filter`). This is because she didn't know what exactly search did for each page.

### Request or proposal

request

### Additional Details

_No response_

### Implementation Suggestions

I have implemented a workaround identified in a [blog post from a few years ago](https://www.better-simple.com/django/2023/08/18/descriptive-django-admin-search/). I don't know how much of that can be reused, but I think the UX should be reasonable.

```python
from my_wonderful_app.models import Plan

class PlanAdmin(admin.ModelAdmin):
search_fields = ["name", "creator__name", "creator__email", "organization__name"]
```

Should result in some text near the search input that reads: "Search by: Plan’s Name, User’s Name, User’s Email, Organization’s Name"

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.