Skip to content

Commit

Permalink
Add Action admin
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyunar committed Jan 31, 2025
1 parent e4602cb commit 0a70bb8
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion actions/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
from django.contrib import admin
from unfold.admin import ModelAdmin

# Register your models here.
from actions.models import Action

from django.utils.translation import gettext_lazy as _


@admin.register(Action)
class ServiceAdmin(ModelAdmin):
list_display = ("name", "service", "handler", "is_active")
search_fields = ("name", "service__name", "handler")
list_filter = ("is_active",)
actions = ["make_active", "make_inactive"]
readonly_fields = ("created_at", "updated_at", "order")

@admin.action(description=_("Make selected Services active"))
def make_active(self, request, queryset):
queryset.update(is_active=True)
self.message_user(request, _("Selected Services are now active."), "success")

@admin.action(description=_("Make selected Services inactive"))
def make_inactive(self, request, queryset):
queryset.update(is_active=False)
self.message_user(request, _("Selected Services are now inactive."), "success")

0 comments on commit 0a70bb8

Please sign in to comment.