Initial commit
This commit is contained in:
commit
5cda7bc309
28 changed files with 1173 additions and 0 deletions
25
yksa_kit/admin.py
Normal file
25
yksa_kit/admin.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import ApiToken
|
||||
|
||||
|
||||
@admin.register(ApiToken)
|
||||
class ApiTokenAdmin(admin.ModelAdmin):
|
||||
list_display = ("name", "kind", "is_active", "created_at", "last_used_at")
|
||||
list_filter = ("kind", "is_active")
|
||||
search_fields = ("name", "notes")
|
||||
readonly_fields = ("token", "created_at", "last_used_at")
|
||||
fieldsets = (
|
||||
(None, {"fields": ("name", "kind", "is_active", "notes")}),
|
||||
("Credential", {"fields": ("token",)}),
|
||||
("Audit", {"fields": ("created_at", "last_used_at")}),
|
||||
)
|
||||
|
||||
def get_readonly_fields(self, request, obj=None):
|
||||
# Hide the generated token on create, reveal it on edit: it is the only
|
||||
# place an operator can ever read it back.
|
||||
if obj is None:
|
||||
return ("created_at", "last_used_at")
|
||||
return self.readonly_fields
|
||||
Loading…
Add table
Add a link
Reference in a new issue