Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #12913. Fields with choices now respect show_hidden_ini…

…tial as a keyword argument to formfield. Backport of r12696 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12697 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e8c768910afd441aa39759de27939eee5d141219 1 parent 8a8366d
Joseph Kocherhans authored March 07, 2010
2  django/db/models/fields/__init__.py
@@ -339,7 +339,7 @@ def formfield(self, form_class=forms.CharField, **kwargs):
339 339
             for k in kwargs.keys():
340 340
                 if k not in ('coerce', 'empty_value', 'choices', 'required',
341 341
                              'widget', 'label', 'initial', 'help_text',
342  
-                             'error_messages'):
  342
+                             'error_messages', 'show_hidden_initial'):
343 343
                     del kwargs[k]
344 344
         defaults.update(kwargs)
345 345
         return form_class(**defaults)
14  tests/regressiontests/model_fields/tests.py
@@ -26,6 +26,20 @@
26 26
             TwoImageFieldTests
27 27
 
28 28
 
  29
+class BasicFieldTests(django.test.TestCase):
  30
+    def test_show_hidden_initial(self):
  31
+        """
  32
+        Regression test for #12913. Make sure fields with choices respect
  33
+        show_hidden_initial as a kwarg to models.Field.formfield()
  34
+        """
  35
+        choices = [(0, 0), (1, 1)]
  36
+        model_field = models.Field(choices=choices)
  37
+        form_field = model_field.formfield(show_hidden_initial=True)
  38
+        self.assertTrue(form_field.show_hidden_initial)
  39
+
  40
+        form_field = model_field.formfield(show_hidden_initial=False)
  41
+        self.assertFalse(form_field.show_hidden_initial)
  42
+
29 43
 class DecimalFieldTests(django.test.TestCase):
30 44
     def test_to_python(self):
31 45
         f = models.DecimalField(max_digits=4, decimal_places=2)

0 notes on commit e8c7689

Please sign in to comment.
Something went wrong with that request. Please try again.