Fixed #3267 -- newforms: Changed database TextField to render as Textarea in form_for_model() forms. Thanks for the patch, Philipp Keller

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4305 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2007-01-10 23:34:37 +00:00
parent fa38ce7207
commit 963ccd7cb4
2 changed files with 11 additions and 4 deletions

View File

@ -757,6 +757,9 @@ class TextField(Field):
def get_manipulator_field_objs(self): def get_manipulator_field_objs(self):
return [oldforms.LargeTextField] return [oldforms.LargeTextField]
def formfield(self, initial=None):
return forms.CharField(required=not self.blank, widget=forms.Textarea, label=capfirst(self.verbose_name), initial=initial)
class TimeField(Field): class TimeField(Field):
empty_strings_allowed = False empty_strings_allowed = False
def __init__(self, verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs): def __init__(self, verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs):

View File

@ -41,6 +41,7 @@ class Article(models.Model):
headline = models.CharField(maxlength=50) headline = models.CharField(maxlength=50)
pub_date = models.DateField() pub_date = models.DateField()
writer = models.ForeignKey(Writer) writer = models.ForeignKey(Writer)
article = models.TextField()
categories = models.ManyToManyField(Category, blank=True) categories = models.ManyToManyField(Category, blank=True)
def __str__(self): def __str__(self):
@ -144,6 +145,7 @@ represented by a ChoiceField.
<option value="1">Mike Royko</option> <option value="1">Mike Royko</option>
<option value="2">Bob Woodward</option> <option value="2">Bob Woodward</option>
</select></td></tr> </select></td></tr>
<tr><th>Article:</th><td><textarea name="article"></textarea></td></tr>
<tr><th>Categories:</th><td><select multiple="multiple" name="categories"> <tr><th>Categories:</th><td><select multiple="multiple" name="categories">
<option value="1">Entertainment</option> <option value="1">Entertainment</option>
<option value="2">It&#39;s a test</option> <option value="2">It&#39;s a test</option>
@ -169,7 +171,7 @@ current values are inserted as 'initial' data in each Field.
>>> print f >>> 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" /></td></tr>
>>> art = Article(headline='Test article', pub_date=datetime.date(1988, 1, 4), writer=w) >>> art = Article(headline='Test article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.')
>>> art.save() >>> art.save()
>>> art.id >>> art.id
1 1
@ -183,12 +185,13 @@ current values are inserted as 'initial' data in each Field.
<option value="1" selected="selected">Mike Royko</option> <option value="1" selected="selected">Mike Royko</option>
<option value="2">Bob Woodward</option> <option value="2">Bob Woodward</option>
</select></li> </select></li>
<li>Article: <textarea name="article">Hello.</textarea></li>
<li>Categories: <select multiple="multiple" name="categories"> <li>Categories: <select multiple="multiple" name="categories">
<option value="1">Entertainment</option> <option value="1">Entertainment</option>
<option value="2">It&#39;s a test</option> <option value="2">It&#39;s a test</option>
<option value="3">Third test</option> <option value="3">Third test</option>
</select></li> </select></li>
>>> f = TestArticleForm({'headline': u'New headline', 'pub_date': u'1988-01-04', 'writer': u'1'}) >>> f = TestArticleForm({'headline': u'New headline', 'pub_date': u'1988-01-04', 'writer': u'1', 'article': 'Hello.'})
>>> f.is_valid() >>> f.is_valid()
True True
>>> new_art = f.save() >>> new_art = f.save()
@ -214,6 +217,7 @@ Add some categories and test the many-to-many form output.
<option value="1" selected="selected">Mike Royko</option> <option value="1" selected="selected">Mike Royko</option>
<option value="2">Bob Woodward</option> <option value="2">Bob Woodward</option>
</select></li> </select></li>
<li>Article: <textarea name="article">Hello.</textarea></li>
<li>Categories: <select multiple="multiple" name="categories"> <li>Categories: <select multiple="multiple" name="categories">
<option value="1" selected="selected">Entertainment</option> <option value="1" selected="selected">Entertainment</option>
<option value="2">It&#39;s a test</option> <option value="2">It&#39;s a test</option>