diff options
author | Michael Manfre | 2022-12-08 12:29:51 -0500 |
---|---|---|
committer | GitHub | 2022-12-08 10:29:51 -0700 |
commit | a576c5b5ed716b8068c02914fd47f38473610590 (patch) | |
tree | 001448f79005826bb7609d1568d9e89b6f675371 /core | |
parent | 08dae900b72e7fdad56cd8d2a7a75422f289e993 (diff) | |
download | takahe-a576c5b5ed716b8068c02914fd47f38473610590.tar.gz takahe-a576c5b5ed716b8068c02914fd47f38473610590.tar.bz2 takahe-a576c5b5ed716b8068c02914fd47f38473610590.zip |
Improve djadmin filtering and search (#149)
Diffstat (limited to 'core')
-rw-r--r-- | core/admin.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/core/admin.py b/core/admin.py index e4a6ad0..a319816 100644 --- a/core/admin.py +++ b/core/admin.py @@ -1,8 +1,33 @@ from django.contrib import admin +from django.utils.translation import gettext_lazy as _ from core.models import Config +class ConfigOptionsTypeFilter(admin.SimpleListFilter): + title = _("config options type") + parameter_name = "type" + + def lookups(self, request, model_admin): + return ( + ("system", _("System")), + ("identity", _("Identity")), + ("user", _("User")), + ) + + def queryset(self, request, queryset): + match self.value(): + case "system": + return queryset.filter(user__isnull=True, identity__isnull=True) + case "identity": + return queryset.exclude(identity__isnull=True) + case "user": + return queryset.exclude(user__isnull=True) + case _: + return queryset + + @admin.register(Config) class ConfigAdmin(admin.ModelAdmin): list_display = ["id", "key", "user", "identity"] + list_filter = (ConfigOptionsTypeFilter,) |