aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--admin.py1
-rw-r--r--models.py8
2 files changed, 9 insertions, 0 deletions
diff --git a/admin.py b/admin.py
index b1edf2f..95b4fd7 100644
--- a/admin.py
+++ b/admin.py
@@ -27,6 +27,7 @@ class GroupAdmin(admin.ModelAdmin):
@admin.register(Subscription)
class SubscriptionAdmin(admin.ModelAdmin):
list_display = ("email", "group", "active",)
+ readonly_fields = ("token",)
@admin.register(Room)
diff --git a/models.py b/models.py
index 9f9387d..7d5efd7 100644
--- a/models.py
+++ b/models.py
@@ -2,6 +2,9 @@ from django.db import models
from django.db.models import Q
from django.utils.text import slugify
+import hashlib
+import os
+
class Timetable(models.Model):
name = models.CharField(max_length=64, unique=True, verbose_name="nom")
@@ -75,6 +78,11 @@ class Subscription(models.Model):
active = models.BooleanField(verbose_name="activé", default=False)
token = models.CharField(max_length=64, unique=True, default="")
+ def save(self):
+ if self.token == "":
+ self.token = hashlib.sha1(os.urandom(128)).hexdigest()
+ super(Subscription, self).save()
+
class Meta:
index_together = ("group", "active",)