feat: use django-objects-actions

This commit is contained in:
2026-09-16 19:07:40 +02:00
parent 4392122cfc
commit f68c4e50e8
7 changed files with 62 additions and 18 deletions
+12 -2
View File
@@ -1,4 +1,9 @@
from django.contrib import admin, messages
from django_object_actions import (
DjangoObjectActions,
action,
takes_instance_or_queryset,
)
from submissions.tasks import sync_event_game_scopes_task
@@ -19,17 +24,22 @@ class GameAdmin(admin.ModelAdmin):
@admin.register(EventGame)
class EventGameAdmin(admin.ModelAdmin):
class EventGameAdmin(DjangoObjectActions, admin.ModelAdmin):
list_display = ["game", "event", "enabled", "has_apibot_token"]
list_filter = ["event", "enabled"]
search_fields = ["game__name", "event__name"]
actions = ["sync_scopes"]
change_actions = ["sync_scopes"]
@admin.display(description="AAndT token", boolean=True)
def has_apibot_token(self, obj):
return bool(obj.apibot_token)
@admin.action(description="Sync scopes from AAndT for selected EventGames")
@action(
label="Sync scopes",
description="Sync scopes from AAndT for selected EventGames",
)
@takes_instance_or_queryset
def sync_scopes(self, request, queryset):
tokened = queryset.exclude(apibot_token__isnull=True).exclude(apibot_token="")
skipped = queryset.count() - tokened.count()