aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/tokenauth/models.py
diff options
context:
space:
mode:
authorMjumbe Wawatu Poe2012-09-07 13:15:24 -0400
committerMjumbe Wawatu Poe2012-09-07 13:15:24 -0400
commit5a3874ee112490937f83fa5700899f3631a14128 (patch)
tree9d1c987a5501d3136ef48bbeb1d77a209aa9ec13 /djangorestframework/tokenauth/models.py
parentf3e65eab6b60a23eeed2178db4f6034ce2c6ac3d (diff)
downloaddjango-rest-framework-5a3874ee112490937f83fa5700899f3631a14128.tar.bz2
Create a key by default if none is specified
Diffstat (limited to 'djangorestframework/tokenauth/models.py')
-rw-r--r--djangorestframework/tokenauth/models.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/djangorestframework/tokenauth/models.py b/djangorestframework/tokenauth/models.py
index 3b9a55bc..b5a9f7b9 100644
--- a/djangorestframework/tokenauth/models.py
+++ b/djangorestframework/tokenauth/models.py
@@ -1,16 +1,22 @@
+import uuid
from django.db import models
class BaseToken(models.Model):
"""
The base abstract authorization token model class.
"""
- key = models.CharField(max_length=32, primary_key=True)
+ key = models.CharField(max_length=32, primary_key=True, blank=True)
user = models.ForeignKey('auth.User')
revoked = models.BooleanField(default=False)
class Meta:
abstract=True
+ def save(self, *args, **kwargs):
+ if not self.key:
+ self.key = uuid.uuid4().hex
+ return super(BaseToken, self).save(*args, **kwargs)
+
class Token(BaseToken):
"""