From 963ccd7cb4c923a70dfcf4b321fa74a099c69948 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Wed, 10 Jan 2007 23:34:37 +0000 Subject: [PATCH] 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 --- django/db/models/fields/__init__.py | 7 +++++-- tests/modeltests/model_forms/models.py | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index e982480815..557286164b 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.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 @@ class TimeField(Field): 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 @@ class URLField(CharField): 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): diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index e2335c9f3e..620565721c 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -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 @@ represented by a ChoiceField. +Article: Categories: ->>> 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 @@ current values are inserted as 'initial' data in each Field. +
  • Article:
  • Categories:
  • ->>> 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 @@ Add some categories and test the many-to-many form output. +
  • Article:
  • Categories: