Skip to content

Include the fields being searched in the admin #129

@tim-schilling

Description

@tim-schilling

Code of Conduct

  • 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. I don't know how much of that can be reused, but I think the UX should be reasonable.

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Idea

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions