Allow search custom fields on a custom user model
See original GitHub issueIs 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:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@favoyang I already push the PR 😄 thanks for your help, I am waiting for a review
@imansyed000 LGTB, wait for a core member to review.