mirror of https://github.com/django/django.git
newforms: Changed database Field formfield() methods to pass help_text to the formfield help_text
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4442 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
cf75fcc832
commit
829e4c70f8
|
@ -336,7 +336,7 @@ class Field(object):
|
|||
|
||||
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 @@ class BooleanField(Field):
|
|||
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 @@ class CharField(Field):
|
|||
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 @@ class DateField(Field):
|
|||
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 @@ class DateTimeField(DateField):
|
|||
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 @@ class EmailField(CharField):
|
|||
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 @@ class IntegerField(Field):
|
|||
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 @@ class TextField(Field):
|
|||
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 @@ class TimeField(Field):
|
|||
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 @@ class URLField(CharField):
|
|||
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)
|
||||
|
||||
|
|
|
@ -549,7 +549,7 @@ class ForeignKey(RelatedField, Field):
|
|||
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 @@ class OneToOneField(RelatedField, IntegerField):
|
|||
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 @@ class ManyToManyField(RelatedField, Field):
|
|||
# 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)
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class Category(models.Model):
|
|||
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 @@ represented by a ChoiceField.
|
|||
<option value="1">Entertainment</option>
|
||||
<option value="2">It'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 @@ current values are inserted as 'initial' data in each Field.
|
|||
>>> 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 @@ current values are inserted as 'initial' data in each Field.
|
|||
<option value="1">Entertainment</option>
|
||||
<option value="2">It'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 @@ Add some categories and test the many-to-many form output.
|
|||
<option value="1" selected="selected">Entertainment</option>
|
||||
<option value="2">It'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']})
|
||||
|
|
Loading…
Reference in New Issue