From bf3b276e3922ebd1d86b8c58ab22191a3ef8277b Mon Sep 17 00:00:00 2001 From: "Andreas (@xAndy) Zimmermann" Date: Thu, 21 Apr 2022 00:53:53 +0200 Subject: [PATCH] resend invite sms in admin backend, admin view improvements --- shiftregister/app/admin.py | 18 ++++++++++++++++-- shiftregister/app/models.py | 5 ++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/shiftregister/app/admin.py b/shiftregister/app/admin.py index e33a2e8..8e59132 100644 --- a/shiftregister/app/admin.py +++ b/shiftregister/app/admin.py @@ -19,10 +19,24 @@ class ShiftAdmin(admin.ModelAdmin): return object.room.required_helpers - object.shiftregistration_set.count() -# admin.site.register(Shift) +def send_login(modeladmin, request, queryset): + for helper in queryset: + helper.send_confirmation() + + +class RegistationInline(admin.TabularInline): + model = ShiftRegistration + + +@admin.register(Helper) +class HelperAdmin(admin.ModelAdmin): + readonly_fields = ("phone",) + fields = ("name", "phone", "number_validated") + list_display = ("name",) + inlines = (RegistationInline,) + actions = (send_login,) -admin.site.register(Helper) admin.site.register(ShiftRegistration) admin.site.register(Message) admin.site.register(LoginToken) diff --git a/shiftregister/app/models.py b/shiftregister/app/models.py index 61b96bd..b268d71 100644 --- a/shiftregister/app/models.py +++ b/shiftregister/app/models.py @@ -31,7 +31,7 @@ class Shift(models.Model): class Helper(models.Model): # todo: add propper phone number validation, maybe even country code? - phone = models.CharField(max_length=200, primary_key=True) + phone = models.CharField(max_length=200, primary_key=True, editable=False) name = models.CharField(max_length=200) # change this to a generic state variable to allow for number blocking/account deactivation? number_validated = models.BooleanField(default=False) @@ -86,6 +86,9 @@ class ShiftRegistration(models.Model): shift__start_at__lte=timezone.now() + timedelta(minutes=60), ) + def __str__(self): + return f"{self.helper.name}: {self.shift}" + class Message(models.Model): # remove limit and send long messages in multiple messages?