2012-09-07 21:15:24 +04:00
|
|
|
import uuid
|
2012-09-07 20:53:39 +04:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
class BaseToken(models.Model):
|
|
|
|
"""
|
|
|
|
The base abstract authorization token model class.
|
|
|
|
"""
|
2012-09-07 21:15:24 +04:00
|
|
|
key = models.CharField(max_length=32, primary_key=True, blank=True)
|
2012-09-07 20:53:39 +04:00
|
|
|
user = models.ForeignKey('auth.User')
|
|
|
|
revoked = models.BooleanField(default=False)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract=True
|
|
|
|
|
2012-09-07 21:15:24 +04:00
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
if not self.key:
|
|
|
|
self.key = uuid.uuid4().hex
|
|
|
|
return super(BaseToken, self).save(*args, **kwargs)
|
|
|
|
|
2012-09-07 20:53:39 +04:00
|
|
|
|
|
|
|
class Token(BaseToken):
|
|
|
|
"""
|
|
|
|
The default authorization token model class.
|
|
|
|
"""
|
|
|
|
pass
|