Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
feat(admin): add searchable dropdowns for user lists in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
trowik committed Sep 16, 2022
1 parent 3be293c commit 4c01054
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 14 additions & 2 deletions timed/employment/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from django import forms
from django.contrib import admin
from django.contrib.admin.widgets import AutocompleteSelect
from django.contrib.auth.admin import UserAdmin
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
Expand All @@ -21,7 +22,11 @@ class SupervisorForm(forms.ModelForm):

# Change the label of the supervisor through table attribute to_user
to_user = forms.ModelChoiceField(
queryset=models.User.objects.all(), label=_("supervised by")
queryset=models.User.objects.all(),
label=_("supervised by"),
widget=AutocompleteSelect(
models.User.supervisors.through.to_user.field, admin_site=admin.site
),
)

class Meta:
Expand All @@ -36,7 +41,11 @@ class SuperviseeForm(forms.ModelForm):

# Change the label of the supervisor through table attribute from_user
from_user = forms.ModelChoiceField(
queryset=models.User.objects.all(), label=_("supervising")
queryset=models.User.objects.all(),
label=_("supervising"),
widget=AutocompleteSelect(
models.User.supervisors.through.from_user.field, admin_site=admin.site
),
)

class Meta:
Expand All @@ -47,6 +56,7 @@ class Meta:


class SupervisorInline(admin.TabularInline):
autocomplete_fields = ["to_user"]
form = SupervisorForm
model = models.User.supervisors.through
extra = 0
Expand All @@ -56,6 +66,7 @@ class SupervisorInline(admin.TabularInline):


class SuperviseeInline(admin.TabularInline):
autocomplete_fields = ["from_user"]
form = SuperviseeForm
model = models.User.supervisors.through
extra = 0
Expand Down Expand Up @@ -143,6 +154,7 @@ class UserAdmin(UserAdmin):
AbsenceCreditInline,
]
list_display = ("username", "first_name", "last_name", "is_staff", "is_active")
search_fields = ["username"]

actions = [
"disable_users",
Expand Down
3 changes: 3 additions & 0 deletions timed/projects/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@


class CustomerAssigneeInline(admin.TabularInline):
autocomplete_fields = ["user"]
model = models.CustomerAssignee
extra = 0


class ProjectAssigneeInline(NestedStackedInline):
autocomplete_fields = ["user"]
model = models.ProjectAssignee
extra = 0


class TaskAssigneeInline(NestedStackedInline):
autocomplete_fields = ["user"]
model = models.TaskAssignee
extra = 1

Expand Down

0 comments on commit 4c01054

Please sign in to comment.