Fix GH-41: re-add get_FOO_display method to models with StatusField.

This commit is contained in:
Carl Meyer 2013-05-02 11:33:48 -06:00
parent 7aa54341c4
commit 216d0b7095
3 changed files with 13 additions and 1 deletions

View file

@ -4,6 +4,8 @@ CHANGES
tip (unreleased)
----------------
- Fixed lack of ``get_FOO_display`` method for ``StatusField``. Fixes GH-41.
1.3.1 (2013.04.11)
------------------
@ -11,8 +13,10 @@ tip (unreleased)
- Added explicit default to ``BooleanField`` in tests, for Django trunk
compatibility.
- Fix intermittent ``StatusField`` bug. Fixes GH-29.
- Fixed intermittent ``StatusField`` bug. Fixes GH-29.
- Added Python 3 support
- Dropped support for Django 1.2 and 1.3. Django 1.4.2+ required.

View file

@ -61,6 +61,10 @@ class StatusField(models.CharField):
def contribute_to_class(self, cls, name):
models.signals.class_prepared.connect(self.prepare_class, sender=cls)
# we don't set the real choices until class_prepared (so we can rely on
# the STATUS class attr being available), but we need to set some dummy
# choices now so the super method will add the get_FOO_display method
self._choices = [(0, 'dummy')]
super(StatusField, self).contribute_to_class(cls, name)

View file

@ -181,6 +181,10 @@ class StatusFieldTests(TestCase):
# this model has no STATUS attribute, so checking for it would error
field.prepare_class(Article)
def test_get_status_display(self):
instance = StatusFieldDefaultFilled()
self.assertEqual(instance.get_status_display(), "Yes")
class ChoicesTests(TestCase):
def setUp(self):