aboutsummaryrefslogtreecommitdiff
path: root/models.py
diff options
context:
space:
mode:
authorAlban Gruin2017-01-22 18:21:49 +0100
committerAlban Gruin2017-01-22 18:21:49 +0100
commit6a9464882f74bc8a85ad86d098f8b4da04c854ca (patch)
tree155564608e89787629069adc358aa8c812590ed9 /models.py
parent35ecadcbe283b2c1368141be5bec16d66c443f7c (diff)
Génération automatique d'un token
Diffstat (limited to 'models.py')
-rw-r--r--models.py8
1 files changed, 8 insertions, 0 deletions
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",)