Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
0d156fc2
Commit
0d156fc2
authored
3 years ago
by
Bastien Abadie
Browse files
Options
Downloads
Plain Diff
Merge branch 'fix-admin-user-search' into 'master'
Fix search in user admin Closes
#964
See merge request
!1637
parents
a3fa94b3
85283285
No related branches found
No related tags found
1 merge request
!1637
Fix search in user admin
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
arkindex/users/admin.py
+10
-1
10 additions, 1 deletion
arkindex/users/admin.py
with
10 additions
and
1 deletion
arkindex/users/admin.py
+
10
−
1
View file @
0d156fc2
...
...
@@ -4,6 +4,7 @@ from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from
django.contrib.auth.forms
import
ReadOnlyPasswordHashField
from
django.contrib.auth.models
import
Group
as
BaseGroup
from
django.contrib.contenttypes.admin
import
GenericTabularInline
from
django.db.models.functions
import
Collate
from
enumfields.admin
import
EnumFieldListFilter
from
arkindex.users.models
import
Group
,
OAuthCredentials
,
Right
,
User
,
UserScope
...
...
@@ -76,10 +77,18 @@ class UserAdmin(BaseUserAdmin):
'
fields
'
:
(
'
email
'
,
'
password1
'
,
'
password2
'
)}
),
)
search_fields
=
(
'
email
'
,)
search_fields
=
(
'
searchable_
email
'
,)
ordering
=
(
'
-created
'
,
'
email
'
,)
filter_horizontal
=
()
def
get_queryset
(
self
,
request
):
qs
=
super
().
get_queryset
(
request
)
# Django's search uses ILIKE, but LIKE is not supported in PostgreSQL with nondeterministic collations.
# We are using a case-insensitive collation to get unique case-insensitive emails, so to search properly,
# we first have to set the collation back to its default value, making it case-sensitive again;
# since Django uses ILIKE, it will be case-insensitive anyway.
return
qs
.
annotate
(
searchable_email
=
Collate
(
'
email
'
,
'
default
'
))
class
UserScopeAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
'
user
'
,
'
scope
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment