mirror of
https://github.com/Hopiu/django-model-utils.git
synced 2026-05-12 12:13:08 +00:00
Choices should be indexable as if it were a two-tuple
This commit is contained in:
parent
acbf46abb2
commit
f64f16b053
2 changed files with 13 additions and 1 deletions
|
|
@ -102,6 +102,9 @@ class Choices(object):
|
|||
except KeyError:
|
||||
raise AttributeError(attname)
|
||||
|
||||
def __getitem__(self, index):
|
||||
return self._choices[index]
|
||||
|
||||
def __repr__(self):
|
||||
return '%s(%s)' % (self.__class__.__name__,
|
||||
', '.join(("'%s'" % i[0] for i in self._choices)))
|
||||
|
|
|
|||
|
|
@ -105,6 +105,9 @@ class ChoicesTests(TestCase):
|
|||
def test_getattr(self):
|
||||
self.assertEquals(self.STATUS.DRAFT, 'DRAFT')
|
||||
|
||||
def test_indexing(self):
|
||||
self.assertEquals(self.STATUS[1], ('PUBLISHED', 'PUBLISHED'))
|
||||
|
||||
def test_iteration(self):
|
||||
self.assertEquals(tuple(self.STATUS), (('DRAFT', 'DRAFT'), ('PUBLISHED', 'PUBLISHED')))
|
||||
|
||||
|
|
@ -124,9 +127,15 @@ class LabelChoicesTests(ChoicesTests):
|
|||
('DELETED', 'DELETED'))
|
||||
)
|
||||
|
||||
def test_display(self):
|
||||
def test_indexing(self):
|
||||
self.assertEquals(self.STATUS[1], ('PUBLISHED', 'is published'))
|
||||
|
||||
def test_default(self):
|
||||
self.assertEquals(self.STATUS.DELETED, 'DELETED')
|
||||
|
||||
def test_provided(self):
|
||||
self.assertEquals(self.STATUS.DRAFT, 'DRAFT')
|
||||
|
||||
|
||||
class InheritanceCastModelTests(TestCase):
|
||||
def setUp(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue