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

[1.0.X\ Fixed #10156: ModelMultipleChoiceField.clean now does a single query instead of O(N). Thanks, Alex Gaynor. Also, I ported a few more doctests to unittests. Backport of r10582 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10583 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss
2009-04-18 15:52:58 +00:00
parent c17547ac50
commit 2ee33cf63b
3 changed files with 73 additions and 43 deletions

View File

@@ -1,47 +1,16 @@
import os
from django.db import models
from django import forms
class Person(models.Model):
name = models.CharField(max_length=100)
class Triple(models.Model):
left = models.IntegerField()
middle = models.IntegerField()
right = models.IntegerField()
def __unicode__(self):
return u"%d, %d, %d" % (self.left, self.middle, self.right)
class Meta:
unique_together = (('left', 'middle'), ('middle', 'right'))
class FilePathModel(models.Model):
path = models.FilePathField(path=os.path.dirname(__file__), match=".*\.py$", blank=True)
__test__ = {'API_TESTS': """
When the same field is involved in multiple unique_together constraints, we
need to make sure we don't remove the data for it before doing all the
validation checking (not just failing after the first one).
>>> _ = Triple.objects.create(left=1, middle=2, right=3)
>>> class TripleForm(forms.ModelForm):
... class Meta:
... model = Triple
>>> form = TripleForm({'left': '1', 'middle': '2', 'right': '3'})
>>> form.is_valid()
False
>>> form = TripleForm({'left': '1', 'middle': '3', 'right': '1'})
>>> form.is_valid()
True
# Regression test for #8842: FilePathField(blank=True)
>>> class FPForm(forms.ModelForm):
... class Meta:
... model = FilePathModel
>>> form = FPForm()
>>> names = [c[1] for c in form['path'].field.choices]
>>> names.sort()
>>> names
['---------', '__init__.py', 'models.py']
"""}