Permalink
Browse files

Fixed #3267 -- newforms: Changed database TextField to render as Text…

…area 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
  • Loading branch information...
1 parent fa38ce7 commit 963ccd7cb4c923a70dfcf4b321fa74a099c69948 @adrianholovaty adrianholovaty committed Jan 10, 2007
Showing with 11 additions and 4 deletions.
  1. +5 −2 django/db/models/fields/__init__.py
  2. +6 −2 tests/modeltests/model_forms/models.py
@@ -757,6 +757,9 @@ class TextField(Field):
def get_manipulator_field_objs(self):
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):
empty_strings_allowed = False
def __init__(self, verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs):
@@ -802,7 +805,7 @@ def formfield(self, initial=None):
class URLField(CharField):
def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs):
- kwargs['maxlength'] = kwargs.get('maxlength', 200)
+ kwargs['maxlength'] = kwargs.get('maxlength', 200)
if verify_exists:
kwargs.setdefault('validator_list', []).append(validators.isExistingURL)
self.verify_exists = verify_exists
@@ -811,7 +814,7 @@ def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs):
def get_manipulator_field_objs(self):
return [oldforms.URLField]
- def get_internal_type(self):
+ def get_internal_type(self):
return "CharField"
def formfield(self, initial=None):
@@ -41,6 +41,7 @@ class Article(models.Model):
headline = models.CharField(maxlength=50)
pub_date = models.DateField()
writer = models.ForeignKey(Writer)
+ article = models.TextField()
categories = models.ManyToManyField(Category, blank=True)
def __str__(self):
@@ -144,6 +145,7 @@ def __str__(self):
<option value="1">Mike Royko</option>
<option value="2">Bob Woodward</option>
</select></td></tr>
+<tr><th>Article:</th><td><textarea name="article"></textarea></td></tr>
<tr><th>Categories:</th><td><select multiple="multiple" name="categories">
<option value="1">Entertainment</option>
<option value="2">It&#39;s a test</option>
@@ -169,7 +171,7 @@ def __str__(self):
>>> print f
<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.id
1
@@ -183,12 +185,13 @@ def __str__(self):
<option value="1" selected="selected">Mike Royko</option>
<option value="2">Bob Woodward</option>
</select></li>
+<li>Article: <textarea name="article">Hello.</textarea></li>
<li>Categories: <select multiple="multiple" name="categories">
<option value="1">Entertainment</option>
<option value="2">It&#39;s a test</option>
<option value="3">Third test</option>
</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()
True
>>> new_art = f.save()
@@ -214,6 +217,7 @@ def __str__(self):
<option value="1" selected="selected">Mike Royko</option>
<option value="2">Bob Woodward</option>
</select></li>
+<li>Article: <textarea name="article">Hello.</textarea></li>
<li>Categories: <select multiple="multiple" name="categories">
<option value="1" selected="selected">Entertainment</option>
<option value="2">It&#39;s a test</option>

0 comments on commit 963ccd7

Please sign in to comment.