question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow search custom fields on a custom user model

See original GitHub issue

Is your proposal related to a problem?

Current wagtail admin user search only allows search on four hard-coded fields: username, first_name, last_name, and email. Would be good if developers can specify custom fields via User.search_fields.

Describe the solution you’d like

If User.search_fields exists, join extra fields to the search term.

    if 'q' in request.GET:
        form = SearchForm(request.GET, placeholder=_("Search users"))
        if form.is_valid():
            q = form.cleaned_data['q']
            is_searching = True
            conditions = Q()

            for term in q.split():
                if 'username' in model_fields:
                    conditions |= Q(username__icontains=term)

                if 'first_name' in model_fields:
                    conditions |= Q(first_name__icontains=term)

                if 'last_name' in model_fields:
                    conditions |= Q(last_name__icontains=term)

                if 'email' in model_fields:
                    conditions |= Q(email__icontains=term)

===>      # TODO:  check search_fields  and join it.

            users = User.objects.filter(group_filter & conditions)

Describe alternatives you’ve considered

n/a

Additional context

One issue is that the matched content is not visible via the user listing, but developers can just override the list.html to show custom fields.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
y-martinezcommented, Mar 15, 2021

@favoyang I already push the PR 😄 thanks for your help, I am waiting for a review

0reactions
favoyangcommented, Jun 17, 2021

@imansyed000 LGTB, wait for a core member to review.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use Custom Fields to Run Provider Searches - Salesforce Help
From Object Manager, find and select Care Provider Searchable Field. Create a text field to map to the custom field that you want...
Read more >
Python Django - How to add custom fields to the User Model
Django #Python # UserModel #DjangoUsers Welcome to the Django for Everyone Playlist! This series of videos, will cover intermediate Django ...
Read more >
Extending the User model with custom fields in Django
Substituting a custom User model ; from django.contrib.auth.models import ; import post_save class ; #other fields here def ; self): return ; def...
Read more >
User Custom Fields - SupportPal Documentation
Visit Settings -> Users -> User Custom Fields. Search for the custom field you wish to delete (see Searching for Custom Fields). Click...
Read more >
Look up search on 2 custom fields instead standard name field
You can't do this using the standard lookup functionality, when searching for custom objects only the "Name" field is searched.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found