summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/model_forms/models.py20
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