summaryrefslogtreecommitdiff
path: root/tests/regressiontests/model_fields/models.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2008-07-27 07:22:39 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2008-07-27 07:22:39 +0000
commit661f62be3c5f810fddd3b33bcbdfe33a3077a66d (patch)
tree427d6dcabcaf5a39bb185980768973310d7ab4fd /tests/regressiontests/model_fields/models.py
parent0e629b01c0470d46be367ff394bbe345d53a9883 (diff)
Fixed #7913 -- Corrected backwards incompatible parts of [7977] when optgroup handling was added to field choices (Ticket #4412). Thanks to Michael Elsdorfer (miracle2k) for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8102 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/model_fields/models.py')
-rw-r--r--tests/regressiontests/model_fields/models.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/regressiontests/model_fields/models.py b/tests/regressiontests/model_fields/models.py
index 7e07227961..9936184606 100644
--- a/tests/regressiontests/model_fields/models.py
+++ b/tests/regressiontests/model_fields/models.py
@@ -11,6 +11,22 @@ class Bar(models.Model):
b = models.CharField(max_length=10)
a = models.ForeignKey(Foo, default=get_foo)
+class Whiz(models.Model):
+ CHOICES = (
+ ('Group 1', (
+ (1,'First'),
+ (2,'Second'),
+ )
+ ),
+ ('Group 2', (
+ (3,'Third'),
+ (4,'Fourth'),
+ )
+ ),
+ (0,'Other'),
+ )
+ c = models.IntegerField(choices=CHOICES, null=True)
+
__test__ = {'API_TESTS':"""
# Create a couple of Places.
>>> f = Foo.objects.create(a='abc')
@@ -21,4 +37,39 @@ __test__ = {'API_TESTS':"""
<Foo: Foo object>
>>> b.save()
+# Regression tests for #7913
+# Check that get_choices and get_flatchoices interact with
+# get_FIELD_display to return the expected values.
+
+# Test a nested value
+>>> w = Whiz(c=1)
+>>> w.save()
+>>> w.get_c_display()
+u'First'
+
+# Test a top level value
+>>> w.c = 0
+>>> w.save()
+>>> w.get_c_display()
+u'Other'
+
+# Test an invalid data value
+>>> w.c = 9
+>>> w.save()
+>>> w.get_c_display()
+9
+
+# Test a blank data value
+>>> w.c = None
+>>> w.save()
+>>> print w.get_c_display()
+None
+
+# Test an empty data value
+>>> w.c = ''
+>>> w.save()
+>>> w.get_c_display()
+u''
+
+
"""}