Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@adrianholovaty adrianholovaty authored
View
20 django/db/models/fields/__init__.py
@@ -336,7 +336,7 @@ def _get_choices(self):
def formfield(self, **kwargs):
"Returns a django.newforms.Field instance for this database Field."
- defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name)}
+ defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
defaults.update(kwargs)
return forms.CharField(**defaults)
@@ -398,7 +398,7 @@ def get_manipulator_field_objs(self):
return [oldforms.CheckboxField]
def formfield(self, **kwargs):
- defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name)}
+ defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
defaults.update(kwargs)
return forms.BooleanField(**defaults)
@@ -417,7 +417,7 @@ def to_python(self, value):
return str(value)
def formfield(self, **kwargs):
- defaults = {'max_length': self.maxlength, 'required': not self.blank, 'label': capfirst(self.verbose_name)}
+ defaults = {'max_length': self.maxlength, 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
defaults.update(kwargs)
return forms.CharField(**defaults)
@@ -493,7 +493,7 @@ def flatten_data(self, follow, obj=None):
return {self.attname: (val is not None and val.strftime("%Y-%m-%d") or '')}
def formfield(self, **kwargs):
- defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name)}
+ defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
defaults.update(kwargs)
return forms.DateField(**defaults)
@@ -556,7 +556,7 @@ def flatten_data(self,follow, obj = None):
time_field: (val is not None and val.strftime("%H:%M:%S") or '')}
def formfield(self, **kwargs):
- defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name)}
+ defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
defaults.update(kwargs)
return forms.DateTimeField(**defaults)
@@ -575,7 +575,7 @@ def validate(self, field_data, all_data):
validators.isValidEmail(field_data, all_data)
def formfield(self, **kwargs):
- defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name)}
+ defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
defaults.update(kwargs)
return forms.EmailField(**defaults)
@@ -712,7 +712,7 @@ def get_manipulator_field_objs(self):
return [oldforms.IntegerField]
def formfield(self, **kwargs):
- defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name)}
+ defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
defaults.update(kwargs)
return forms.IntegerField(**defaults)
@@ -771,7 +771,7 @@ def get_manipulator_field_objs(self):
return [oldforms.LargeTextField]
def formfield(self, **kwargs):
- defaults = {'required': not self.blank, 'widget': forms.Textarea, 'label': capfirst(self.verbose_name)}
+ defaults = {'required': not self.blank, 'widget': forms.Textarea, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
defaults.update(kwargs)
return forms.CharField(**defaults)
@@ -816,7 +816,7 @@ def flatten_data(self,follow, obj = None):
return {self.attname: (val is not None and val.strftime("%H:%M:%S") or '')}
def formfield(self, **kwargs):
- defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name)}
+ defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
defaults.update(kwargs)
return forms.TimeField(**defaults)
@@ -835,7 +835,7 @@ def get_internal_type(self):
return "CharField"
def formfield(self, **kwargs):
- defaults = {'required': not self.blank, 'verify_exists': self.verify_exists, 'label': capfirst(self.verbose_name)}
+ defaults = {'required': not self.blank, 'verify_exists': self.verify_exists, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
defaults.update(kwargs)
return forms.URLField(**defaults)
View
6 django/db/models/fields/related.py
@@ -549,7 +549,7 @@ def contribute_to_related_class(self, cls, related):
setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related))
def formfield(self, **kwargs):
- defaults = {'choices': self.get_choices_default(), 'required': not self.blank, 'label': capfirst(self.verbose_name)}
+ defaults = {'choices': self.get_choices_default(), 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
defaults.update(kwargs)
return forms.ChoiceField(**defaults)
@@ -615,7 +615,7 @@ def contribute_to_related_class(self, cls, related):
cls._meta.one_to_one_field = self
def formfield(self, **kwargs):
- defaults = {'choices': self.get_choices_default(), 'required': not self.blank, 'label': capfirst(self.verbose_name)}
+ defaults = {'choices': self.get_choices_default(), 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
defaults.update(kwargs)
return forms.ChoiceField(**kwargs)
@@ -738,7 +738,7 @@ def formfield(self, **kwargs):
# MultipleChoiceField takes a list of IDs.
if kwargs.get('initial') is not None:
kwargs['initial'] = [i._get_pk_val() for i in kwargs['initial']]
- defaults = {'choices': self.get_choices_default(), 'required': not self.blank, 'label': capfirst(self.verbose_name)}
+ defaults = {'choices': self.get_choices_default(), 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
defaults.update(kwargs)
return forms.MultipleChoiceField(**defaults)
View
10 tests/modeltests/model_forms/models.py
@@ -32,7 +32,7 @@ def __str__(self):
return self.name
class Writer(models.Model):
- name = models.CharField(maxlength=50)
+ name = models.CharField(maxlength=50, help_text='Use both first and last names.')
def __str__(self):
return self.name
@@ -150,7 +150,7 @@ def __str__(self):
<option value="1">Entertainment</option>
<option value="2">It&#39;s a test</option>
<option value="3">Third test</option>
-</select></td></tr>
+</select><br /> Hold down "Control", or "Command" on a Mac, to select more than one.</td></tr>
You can pass a custom Form class to form_for_model. Make sure it's a
subclass of BaseForm, not Form.
@@ -169,7 +169,7 @@ def __str__(self):
>>> RoykoForm = form_for_instance(w)
>>> f = RoykoForm(auto_id=False)
>>> print f
-<tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /></td></tr>
+<tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br />Use both first and last names.</td></tr>
>>> art = Article(headline='Test article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.')
>>> art.save()
@@ -190,7 +190,7 @@ def __str__(self):
<option value="1">Entertainment</option>
<option value="2">It&#39;s a test</option>
<option value="3">Third test</option>
-</select></li>
+</select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>
>>> f = TestArticleForm({'headline': u'New headline', 'pub_date': u'1988-01-04', 'writer': u'1', 'article': 'Hello.'})
>>> f.is_valid()
True
@@ -222,7 +222,7 @@ def __str__(self):
<option value="1" selected="selected">Entertainment</option>
<option value="2">It&#39;s a test</option>
<option value="3">Third test</option>
-</select></li>
+</select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>
>>> f = TestArticleForm({'headline': u'New headline', 'pub_date': u'1988-01-04',
... 'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']})
Please sign in to comment.
Something went wrong with that request. Please try again.