1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

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
This commit is contained in:
Karen Tracey
2008-10-21 14:04:24 +00:00
parent a14b98e207
commit 49ef21d9ea
2 changed files with 44 additions and 13 deletions

View File

@@ -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: