2022-11-16 16:23:46 -08:00
|
|
|
from django.contrib import admin
|
2022-12-08 09:29:51 -08:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2022-11-16 16:23:46 -08:00
|
|
|
|
|
|
|
from core.models import Config
|
|
|
|
|
|
|
|
|
2022-12-08 09:29:51 -08:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-11-16 16:23:46 -08:00
|
|
|
@admin.register(Config)
|
|
|
|
class ConfigAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ["id", "key", "user", "identity"]
|
2022-12-08 09:29:51 -08:00
|
|
|
list_filter = (ConfigOptionsTypeFilter,)
|