1from __future__ import annotations
2
3from plain.admin.views import (
4 AdminModelDetailView,
5 AdminModelListView,
6 AdminViewset,
7 register_viewset,
8)
9from plain.cache.models import CachedItem
10from plain.models import QuerySet
11
12
13@register_viewset
14class CachedItemViewset(AdminViewset):
15 class ListView(AdminModelListView):
16 nav_section = "Cache"
17 nav_icon = "database"
18 model = CachedItem
19 title = "Cached items"
20 description = "Database cache entries with expiration times."
21 fields = [
22 "key",
23 "created_at",
24 "expires_at",
25 "updated_at",
26 ]
27 queryset_order = ["-id"]
28 allow_global_search = False
29
30 def get_initial_queryset(self) -> QuerySet[CachedItem]:
31 return (
32 super()
33 .get_initial_queryset()
34 .only("key", "created_at", "expires_at", "updated_at")
35 )
36
37 class DetailView(AdminModelDetailView):
38 model = CachedItem
39 title = "Cached item"