From f4ffb6f256c88f98cf630992ce6080d21bb83fcb Mon Sep 17 00:00:00 2001 From: David Taylor Date: Sun, 19 Apr 2015 17:06:03 +0100 Subject: [PATCH] Added api key stuff to profile model --- RIGS/models.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/RIGS/models.py b/RIGS/models.py index f31ff77d..79736131 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -7,6 +7,8 @@ from django.conf import settings from django.utils.functional import cached_property from django.utils.encoding import python_2_unicode_compatible import reversion +import string +import random from decimal import Decimal @@ -14,6 +16,14 @@ from decimal import Decimal class Profile(AbstractUser): initials = models.CharField(max_length=5, unique=True, null=True, blank=False) phone = models.CharField(max_length=13, null=True, blank=True) + api_key = models.CharField(max_length=40,blank=False,editable=True,default=lambda: make_api_key()) + + @classmethod + def make_api_key(cls): + size=20 + chars=string.ascii_letters + string.digits + new_api_key = ''.join(random.choice(chars) for x in range(size)) + return new_api_key; @property def profile_picture(self): @@ -26,7 +36,6 @@ class Profile(AbstractUser): def name(self): return self.get_full_name() + ' "' + self.initials + '"' - class RevisionMixin(object): @property def last_edited_at(self):