add __str__ and __unicode__ methods to models so they look better in the admin pages

This commit is contained in:
Chris Gough 2015-05-30 21:54:04 +10:00
parent cbcafd5e52
commit e9ed60d16c

View file

@ -21,6 +21,12 @@ class Client(models.Model):
_redirect_uris = models.TextField(default='') _redirect_uris = models.TextField(default='')
def __str__(self):
return self.name
def __unicode__(self):
return self.__str__()
def redirect_uris(): def redirect_uris():
def fget(self): def fget(self):
return self._redirect_uris.splitlines() return self._redirect_uris.splitlines()
@ -40,6 +46,7 @@ class BaseCodeTokenModel(models.Model):
client = models.ForeignKey(Client) client = models.ForeignKey(Client)
expires_at = models.DateTimeField() expires_at = models.DateTimeField()
_scope = models.TextField(default='') _scope = models.TextField(default='')
def scope(): def scope():
def fget(self): def fget(self):
return self._scope.split() return self._scope.split()
@ -51,6 +58,12 @@ class BaseCodeTokenModel(models.Model):
def has_expired(self): def has_expired(self):
return timezone.now() >= self.expires_at return timezone.now() >= self.expires_at
def __str__(self):
return "%s - %s (%s)" % (self.client, self.user, self.expires_at)
def __unicode__(self):
return self.__str__()
class Meta: class Meta:
abstract = True abstract = True