refactor: Refactors registration status updates

Replaces bulk update with individual model saves to possibly
trigger save-related handlers or signals.

Improves code consistency in registration approval process.
This commit is contained in:
Kumi 2024-11-16 21:48:06 +01:00
parent ae1428f416
commit 858a494765
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -11,11 +11,17 @@ class UserRegistrationAdmin(admin.ModelAdmin):
actions = ["approve_registrations", "deny_registrations"]
def approve_registrations(self, request, queryset):
queryset.update(status=UserRegistration.STATUS_APPROVED)
for registration in queryset:
registration.status = UserRegistration.STATUS_APPROVED
registration.save()
self.message_user(request, f"{queryset.count()} registrations approved.")
def deny_registrations(self, request, queryset):
queryset.update(status=UserRegistration.STATUS_DENIED)
for registration in queryset:
registration.status = UserRegistration.STATUS_DENIED
registration.save()
self.message_user(request, f"{queryset.count()} registrations denied.")
approve_registrations.short_description = "Approve selected registrations"