25 lines
884 B
Python
25 lines
884 B
Python
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
|