X-Git-Url: https://git.mdrn.pl/cas.git/blobdiff_plain/6e3dcb6d3a61a9dcd85dc5bf5e44c2d49a5a1cb3..02e4db2d5557aac2b27a4cce164adc6f22f5d0cf:/src/services/models.py diff --git a/src/services/models.py b/src/services/models.py index 593eff2..c7a5d97 100644 --- a/src/services/models.py +++ b/src/services/models.py @@ -1,3 +1,4 @@ +import secrets from django.conf import settings from django.contrib.auth.models import User from django.db import models @@ -20,6 +21,11 @@ class Service(models.Model): def __str__(self): return self.name + def save(self, *args, **kwargs): + if not self.key: + self.key = secrets.token_urlsafe() + return super().save(*args, **kwargs) + def all_users(self): return User.objects.filter( models.Q(service=self) |