Commits

Anonymous committed c41e94c

Choices should be indexable as if it were a two-tuple

Comments (0)

Files changed (2)

model_utils/__init__.py

         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)))

model_utils/tests/tests.py

     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')))
 
             ('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):