from django.utils.translation import ugettext_lazy as _ from django.contrib import admin from .models import NelUser from .views import send_activation_email class NelUserAdmin(admin.ModelAdmin): list_display = ( "email", "date_joined", "last_login", "is_active", "is_staff", "is_superuser", ) readonly_fields = ("date_joined", "last_login") list_filter = ("is_active", "is_staff", "is_superuser") search_fields = ("email",) fieldsets = [ (_("info"), {"fields": ["is_active", "email", "date_joined", "last_login"]}), ( _("user_permissions"), {"fields": ["is_staff", "is_superuser", "groups", "user_permissions"]}, ), (_("misc"), {"fields": ["nsfw_allowed"]}), ] actions = ["resend_activation_link"] def save_model(self, request, obj, form, change): super().save_model(request, obj, form, change) send_activation_email(request, obj) def resend_activation_link(self, request, queryset): for user in queryset: if not user.is_active: send_activation_email(request, user) resend_activation_link.short_description = _("resend_activation_link") admin.site.register(NelUser, NelUserAdmin)