diff options
author | Alban Gruin | 2017-01-22 18:21:49 +0100 |
---|---|---|
committer | Alban Gruin | 2017-01-22 18:21:49 +0100 |
commit | 6a9464882f74bc8a85ad86d098f8b4da04c854ca (patch) | |
tree | 155564608e89787629069adc358aa8c812590ed9 /models.py | |
parent | 35ecadcbe283b2c1368141be5bec16d66c443f7c (diff) |
Génération automatique d'un token
Diffstat (limited to 'models.py')
-rw-r--r-- | models.py | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -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",) |