2023-01-24 21:21:26 -05:00
|
|
|
from django.contrib import admin
|
|
|
|
|
|
|
|
from .models import HIDEvent
|
|
|
|
|
|
|
|
|
2023-04-03 17:16:48 -04:00
|
|
|
class IsRedFilter(admin.SimpleListFilter):
|
|
|
|
title = "Is Red"
|
|
|
|
parameter_name = "is_red"
|
|
|
|
|
|
|
|
def lookups(self, request, model_admin):
|
|
|
|
return (
|
|
|
|
("1", "Yes"),
|
|
|
|
("0", "No"),
|
|
|
|
)
|
|
|
|
|
|
|
|
def queryset(self, request, queryset):
|
|
|
|
if self.value() is None:
|
|
|
|
return queryset
|
|
|
|
else:
|
|
|
|
return queryset.filter(is_red=(self.value() == "1"))
|
|
|
|
|
|
|
|
|
2023-01-24 21:21:26 -05:00
|
|
|
@admin.register(HIDEvent)
|
|
|
|
class HIDEventAdmin(admin.ModelAdmin):
|
2023-04-03 17:17:47 -04:00
|
|
|
search_fields = ["forename", "surname", "cardholder_id"]
|
2023-01-24 21:21:26 -05:00
|
|
|
list_display = ["door_name", "timestamp", "event_type", "description", "is_red"]
|
2023-04-03 17:16:48 -04:00
|
|
|
list_filter = [
|
2023-04-03 21:30:15 -04:00
|
|
|
"timestamp",
|
2023-04-03 17:16:48 -04:00
|
|
|
"door_name",
|
|
|
|
"event_type",
|
|
|
|
IsRedFilter,
|
|
|
|
]
|
2023-04-03 23:15:12 -04:00
|
|
|
readonly_fields = ["decoded_card_number"]
|
2023-04-03 17:16:48 -04:00
|
|
|
|
|
|
|
def get_queryset(self, request):
|
2023-04-03 23:15:12 -04:00
|
|
|
return super().get_queryset(request).with_is_red().with_decoded_card_number()
|
2023-04-03 17:16:48 -04:00
|
|
|
|
|
|
|
@admin.display(boolean=True)
|
|
|
|
def is_red(self, obj):
|
|
|
|
return obj.is_red
|
2023-01-24 21:21:26 -05:00
|
|
|
|
|
|
|
def has_add_permission(self, request, obj=None):
|
|
|
|
return False
|
|
|
|
|
|
|
|
def has_change_permission(self, request, obj=None):
|
|
|
|
return False
|
|
|
|
|
|
|
|
def has_delete_permission(self, request, obj=None):
|
|
|
|
return False
|