Added api key stuff to profile model

This commit is contained in:
David Taylor
2015-04-19 17:06:03 +01:00
parent b7120aa8f3
commit f4ffb6f256

View File

@@ -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):