Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

newforms: Changed database Field formfield() methods to pass help_tex…

…t to the formfield help_text

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4442 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 829e4c70f8953600cad8cb6120552f072473fb6d 1 parent cf75fcc
Adrian Holovaty authored January 28, 2007
20  django/db/models/fields/__init__.py
@@ -336,7 +336,7 @@ def _get_choices(self):
336 336
 
337 337
     def formfield(self, **kwargs):
338 338
         "Returns a django.newforms.Field instance for this database Field."
339  
-        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name)}
  339
+        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
340 340
         defaults.update(kwargs)
341 341
         return forms.CharField(**defaults)
342 342
 
@@ -398,7 +398,7 @@ def get_manipulator_field_objs(self):
398 398
         return [oldforms.CheckboxField]
399 399
 
400 400
     def formfield(self, **kwargs):
401  
-        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name)}
  401
+        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
402 402
         defaults.update(kwargs)
403 403
         return forms.BooleanField(**defaults)
404 404
 
@@ -417,7 +417,7 @@ def to_python(self, value):
417 417
         return str(value)
418 418
 
419 419
     def formfield(self, **kwargs):
420  
-        defaults = {'max_length': self.maxlength, 'required': not self.blank, 'label': capfirst(self.verbose_name)}
  420
+        defaults = {'max_length': self.maxlength, 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
421 421
         defaults.update(kwargs)
422 422
         return forms.CharField(**defaults)
423 423
 
@@ -493,7 +493,7 @@ def flatten_data(self, follow, obj=None):
493 493
         return {self.attname: (val is not None and val.strftime("%Y-%m-%d") or '')}
494 494
 
495 495
     def formfield(self, **kwargs):
496  
-        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name)}
  496
+        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
497 497
         defaults.update(kwargs)
498 498
         return forms.DateField(**defaults)
499 499
 
@@ -556,7 +556,7 @@ def flatten_data(self,follow, obj = None):
556 556
                 time_field: (val is not None and val.strftime("%H:%M:%S") or '')}
557 557
 
558 558
     def formfield(self, **kwargs):
559  
-        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name)}
  559
+        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
560 560
         defaults.update(kwargs)
561 561
         return forms.DateTimeField(**defaults)
562 562
 
@@ -575,7 +575,7 @@ def validate(self, field_data, all_data):
575 575
         validators.isValidEmail(field_data, all_data)
576 576
 
577 577
     def formfield(self, **kwargs):
578  
-        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name)}
  578
+        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
579 579
         defaults.update(kwargs)
580 580
         return forms.EmailField(**defaults)
581 581
 
@@ -712,7 +712,7 @@ def get_manipulator_field_objs(self):
712 712
         return [oldforms.IntegerField]
713 713
 
714 714
     def formfield(self, **kwargs):
715  
-        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name)}
  715
+        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
716 716
         defaults.update(kwargs)
717 717
         return forms.IntegerField(**defaults)
718 718
 
@@ -771,7 +771,7 @@ def get_manipulator_field_objs(self):
771 771
         return [oldforms.LargeTextField]
772 772
 
773 773
     def formfield(self, **kwargs):
774  
-        defaults = {'required': not self.blank, 'widget': forms.Textarea, 'label': capfirst(self.verbose_name)}
  774
+        defaults = {'required': not self.blank, 'widget': forms.Textarea, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
775 775
         defaults.update(kwargs)
776 776
         return forms.CharField(**defaults)
777 777
 
@@ -816,7 +816,7 @@ def flatten_data(self,follow, obj = None):
816 816
         return {self.attname: (val is not None and val.strftime("%H:%M:%S") or '')}
817 817
 
818 818
     def formfield(self, **kwargs):
819  
-        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name)}
  819
+        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
820 820
         defaults.update(kwargs)
821 821
         return forms.TimeField(**defaults)
822 822
 
@@ -835,7 +835,7 @@ def get_internal_type(self):
835 835
         return "CharField"
836 836
 
837 837
     def formfield(self, **kwargs):
838  
-        defaults = {'required': not self.blank, 'verify_exists': self.verify_exists, 'label': capfirst(self.verbose_name)}
  838
+        defaults = {'required': not self.blank, 'verify_exists': self.verify_exists, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
839 839
         defaults.update(kwargs)
840 840
         return forms.URLField(**defaults)
841 841
 
6  django/db/models/fields/related.py
@@ -549,7 +549,7 @@ def contribute_to_related_class(self, cls, related):
@@ -615,7 +615,7 @@ def contribute_to_related_class(self, cls, related):
@@ -738,7 +738,7 @@ def formfield(self, **kwargs):
10  tests/modeltests/model_forms/models.py
@@ -32,7 +32,7 @@ def __str__(self):
32 32
         return self.name
33 33
 
34 34
 class Writer(models.Model):
35  
-    name = models.CharField(maxlength=50)
  35
+    name = models.CharField(maxlength=50, help_text='Use both first and last names.')
36 36
 
37 37
     def __str__(self):
38 38
         return self.name
@@ -150,7 +150,7 @@ def __str__(self):
150 150
 <option value="1">Entertainment</option>
151 151
 <option value="2">It&#39;s a test</option>
152 152
 <option value="3">Third test</option>
153  
-</select></td></tr>
  153
+</select><br /> Hold down "Control", or "Command" on a Mac, to select more than one.</td></tr>
154 154
 
155 155
 You can pass a custom Form class to form_for_model. Make sure it's a
156 156
 subclass of BaseForm, not Form.
@@ -169,7 +169,7 @@ def __str__(self):
169 169
 >>> RoykoForm = form_for_instance(w)
170 170
 >>> f = RoykoForm(auto_id=False)
171 171
 >>> print f
172  
-<tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /></td></tr>
  172
+<tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br />Use both first and last names.</td></tr>
173 173
 
174 174
 >>> art = Article(headline='Test article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.')
175 175
 >>> art.save()
@@ -190,7 +190,7 @@ def __str__(self):
190 190
 <option value="1">Entertainment</option>
191 191
 <option value="2">It&#39;s a test</option>
192 192
 <option value="3">Third test</option>
193  
-</select></li>
  193
+</select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>
194 194
 >>> f = TestArticleForm({'headline': u'New headline', 'pub_date': u'1988-01-04', 'writer': u'1', 'article': 'Hello.'})
195 195
 >>> f.is_valid()
196 196
 True
@@ -222,7 +222,7 @@ def __str__(self):
222 222
 <option value="1" selected="selected">Entertainment</option>
223 223
 <option value="2">It&#39;s a test</option>
224 224
 <option value="3">Third test</option>
225  
-</select></li>
  225
+</select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>
226 226
 
227 227
 >>> f = TestArticleForm({'headline': u'New headline', 'pub_date': u'1988-01-04',
228 228
 ...     'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']})

0 notes on commit 829e4c7

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