1 from django.conf import settings
2 from django.db import models
9 ('pending', 'Pending approval'),
10 ('accepted', 'Accepted'),
11 ('canceled', 'Canceled'),
15 class Nonce(models.Model):
16 token_key = models.CharField(max_length=KEY_SIZE)
17 consumer_key = models.CharField(max_length=KEY_SIZE)
18 key = models.CharField(max_length=255)
20 def __unicode__(self):
21 return u"Nonce %s for %s" % (self.key, self.consumer_key)
24 class Resource(models.Model):
25 name = models.CharField(max_length=255)
26 url = models.TextField(max_length=2047)
27 is_readonly = models.BooleanField(default=True)
30 class Consumer(models.Model):
31 name = models.CharField(max_length=255)
32 description = models.TextField()
33 key = models.CharField(max_length=KEY_SIZE)
34 secret = models.CharField(max_length=SECRET_SIZE)
35 status = models.CharField(max_length=16, choices=CONSUMER_STATES, default='pending')
36 user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, related_name='consumers')
38 def __unicode__(self):
39 return u"Consumer %s with key %s" % (self.name, self.key)
42 class Token(models.Model):
45 TOKEN_TYPES = ((REQUEST, u'Request'), (ACCESS, u'Access'))
47 key = models.CharField(max_length=KEY_SIZE)
48 secret = models.CharField(max_length=SECRET_SIZE)
49 token_type = models.IntegerField(choices=TOKEN_TYPES)
50 timestamp = models.IntegerField()
51 is_approved = models.BooleanField(default=False)
52 user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, related_name='tokens')
53 consumer = models.ForeignKey(Consumer)
55 def __unicode__(self):
56 return u"%s Token %s for %s" % (self.get_token_type_display(), self.key, self.consumer)