Author: jkocherhans
Date: 2010-03-06 19:50:58 -0600 (Sat, 06 Mar 2010)
New Revision: 12696

Modified:
   django/trunk/django/db/models/fields/__init__.py
   django/trunk/tests/regressiontests/model_fields/tests.py
Log:
Fixed #12913. Fields with choices now respect show_hidden_initial as a keyword 
argument to formfield. Thanks, semenov.

Modified: django/trunk/django/db/models/fields/__init__.py
===================================================================
--- django/trunk/django/db/models/fields/__init__.py    2010-03-07 00:52:11 UTC 
(rev 12695)
+++ django/trunk/django/db/models/fields/__init__.py    2010-03-07 01:50:58 UTC 
(rev 12696)
@@ -462,7 +462,7 @@
             for k in kwargs.keys():
                 if k not in ('coerce', 'empty_value', 'choices', 'required',
                              'widget', 'label', 'initial', 'help_text',
-                             'error_messages'):
+                             'error_messages', 'show_hidden_initial'):
                     del kwargs[k]
         defaults.update(kwargs)
         return form_class(**defaults)

Modified: django/trunk/tests/regressiontests/model_fields/tests.py
===================================================================
--- django/trunk/tests/regressiontests/model_fields/tests.py    2010-03-07 
00:52:11 UTC (rev 12695)
+++ django/trunk/tests/regressiontests/model_fields/tests.py    2010-03-07 
01:50:58 UTC (rev 12696)
@@ -26,6 +26,20 @@
             TwoImageFieldTests
 
 
+class BasicFieldTests(django.test.TestCase):
+    def test_show_hidden_initial(self):
+        """
+        Regression test for #12913. Make sure fields with choices respect
+        show_hidden_initial as a kwarg to models.Field.formfield()
+        """
+        choices = [(0, 0), (1, 1)]
+        model_field = models.Field(choices=choices)
+        form_field = model_field.formfield(show_hidden_initial=True)
+        self.assertTrue(form_field.show_hidden_initial)
+
+        form_field = model_field.formfield(show_hidden_initial=False)
+        self.assertFalse(form_field.show_hidden_initial)
+
 class DecimalFieldTests(django.test.TestCase):
     def test_to_python(self):
         f = models.DecimalField(max_digits=4, decimal_places=2)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to