summaryrefslogtreecommitdiff
path: root/tests/modeltests/model_forms
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2008-11-05 19:55:51 +0000
committerKaren Tracey <kmtracey@gmail.com>2008-11-05 19:55:51 +0000
commitdcfafea408a6eec2d35f9bc2f7aaff724ceee36f (patch)
tree381868bcf2b9d5132ef420e0f5c97ee9adb39b24 /tests/modeltests/model_forms
parent8e7eddd59d896d70de733cf7dd94fe0d30744afb (diff)
[1.0.X] Fixed #9218 -- Simplified the fix from #9039 and added tests to ensure this case doesn't break again (and that the simplification didn't break anything).
[9341] from trunk. Also updated svnmerge metadata. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9342 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests/model_forms')
-rw-r--r--tests/modeltests/model_forms/models.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py
index 01728a997e..0489ea81d8 100644
--- a/tests/modeltests/model_forms/models.py
+++ b/tests/modeltests/model_forms/models.py
@@ -158,6 +158,15 @@ class Book(models.Model):
class Meta:
unique_together = ('title', 'author')
+
+class ExplicitPK(models.Model):
+ key = models.CharField(max_length=20, primary_key=True)
+ desc = models.CharField(max_length=20, blank=True, unique=True)
+ class Meta:
+ unique_together = ('key', 'desc')
+
+ def __unicode__(self):
+ return self.key
__test__ = {'API_TESTS': """
>>> from django import forms
@@ -1247,6 +1256,27 @@ True
>>> form.is_valid()
True
+# Test for primary_key being in the form and failing validation.
+>>> class ExplicitPKForm(ModelForm):
+... class Meta:
+... model = ExplicitPK
+... fields = ('key', 'desc',)
+>>> form = ExplicitPKForm({'key': u'', 'desc': u'' })
+>>> form.is_valid()
+False
+
+# Ensure keys and blank character strings are tested for uniqueness.
+>>> form = ExplicitPKForm({'key': u'key1', 'desc': u''})
+>>> form.is_valid()
+True
+>>> form.save()
+<ExplicitPK: key1>
+>>> form = ExplicitPKForm({'key': u'key1', 'desc': u''})
+>>> form.is_valid()
+False
+>>> form.errors
+{'__all__': [u'Explicit pk with this Key and Desc already exists.'], 'key': [u'Explicit pk with this Key already exists.'], 'desc': [u'Explicit pk with this Desc already exists.']}
+
# Choices on CharField and IntegerField
>>> class ArticleForm(ModelForm):
... class Meta: