diff options
author | Karen Tracey <kmtracey@gmail.com> | 2008-10-21 14:04:24 +0000 |
---|---|---|
committer | Karen Tracey <kmtracey@gmail.com> | 2008-10-21 14:04:24 +0000 |
commit | 49ef21d9ea3070aba863af83b22d1ff6dba69f45 (patch) | |
tree | 73c1ec625b080ef3a13f754113af69c5cdde46cc /tests/modeltests | |
parent | a14b98e207bd2987a99e3e816be17e773fd0341f (diff) | |
download | django-49ef21d9ea3070aba863af83b22d1ff6dba69f45.tar.gz |
Fixed #9039 -- Don't perform unique checks on NULL values, since NULL != NULL in SQL.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9239 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests')
-rw-r--r-- | tests/modeltests/model_forms/models.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index 0b99a84cda..96b92a3233 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -145,7 +145,15 @@ class Inventory(models.Model): def __unicode__(self): return self.name - + +class Book(models.Model): + title = models.CharField(max_length=40) + author = models.ForeignKey(Writer, blank=True, null=True) + special_id = models.IntegerField(blank=True, null=True, unique=True) + + class Meta: + unique_together = ('title', 'author') + __test__ = {'API_TESTS': """ >>> from django import forms >>> from django.forms.models import ModelForm, model_to_dict @@ -1201,6 +1209,32 @@ False >>> form.is_valid() True +# Unique & unique together with null values +>>> class BookForm(ModelForm): +... class Meta: +... model = Book +>>> w = Writer.objects.get(name='Mike Royko') +>>> form = BookForm({'title': 'I May Be Wrong But I Doubt It', 'author' : w.pk}) +>>> form.is_valid() +True +>>> form.save() +<Book: Book object> +>>> form = BookForm({'title': 'I May Be Wrong But I Doubt It', 'author' : w.pk}) +>>> form.is_valid() +False +>>> form._errors +{'__all__': [u'Book with this Title and Author already exists.']} +>>> form = BookForm({'title': 'I May Be Wrong But I Doubt It'}) +>>> form.is_valid() +True +>>> form.save() +<Book: Book object> +>>> form = BookForm({'title': 'I May Be Wrong But I Doubt It'}) +>>> form.is_valid() +True +>>> form.save() +<Book: Book object> + # Choices on CharField and IntegerField >>> class ArticleForm(ModelForm): ... class Meta: |