diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-02-14 12:56:49 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-02-14 12:56:49 +0000 |
| commit | 37962ecea79cb9d296645a5324cd91818fed65b3 (patch) | |
| tree | 67225fd54f15c13c0a014759a41637bd3931488d /tests | |
| parent | 5078010a31ea32a6fd2e9c4fce5354b8f838b163 (diff) | |
Fixed #6337. Refs #3632 -- Fixed ModelForms subclassing, to the extent that it can be made to work.
This ended up being an almost complete rewrite of ModelForms.__new__, but
should be backwards compatible (although the text of one error message has
changed, which is only user visible and only if you pass in invalid code).
Documentation updated, also.
This started out as a patch from semenov (many thanks!), but by the time all
the problems were hammered out, little of the original was left. Still, it was
a good starting point.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7112 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/model_forms/models.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index f1fed8f1e1..0d429b2a71 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -64,11 +64,11 @@ class TextFile(models.Model): def __unicode__(self): return self.description - + class ImageFile(models.Model): description = models.CharField(max_length=20) image = models.FileField(upload_to=tempfile.gettempdir()) - + def __unicode__(self): return self.description @@ -160,7 +160,7 @@ familiar with the mechanics. ... model = Article Traceback (most recent call last): ... -ImproperlyConfigured: BadForm defines a different model than its parent. +ImproperlyConfigured: BadForm's base classes define more than one model. >>> class ArticleForm(ModelForm): ... class Meta: @@ -179,6 +179,20 @@ This one is OK since the subclass specifies the same model as the parent. ... model = Category +Subclassing without specifying a Meta on the class will use the parent's Meta +(or the first parent in the MRO if there are multiple parent classes). + +>>> class CategoryForm(ModelForm): +... class Meta: +... model = Category +... exclude = ['url'] +>>> class SubCategoryForm(CategoryForm): +... pass + +>>> print SubCategoryForm() +<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" maxlength="20" /></td></tr> +<tr><th><label for="id_slug">Slug:</label></th><td><input id="id_slug" type="text" name="slug" maxlength="20" /></td></tr> + # Old form_for_x tests ####################################################### >>> from django.newforms import ModelForm, CharField |
