mirror of
https://github.com/django/django.git
synced 2024-12-01 15:42:04 +01:00
Fixed #15559 - distinct queries introduced by [15607] cause errors with some custom model fields
This patch just reverts [15607] until a more satisfying solution can be found. Refs #11707 git-svn-id: http://code.djangoproject.com/svn/django/trunk@15791 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f17fc56602
commit
0a3aae8362
@ -910,7 +910,7 @@ class ForeignKey(RelatedField, Field):
|
|||||||
db = kwargs.pop('using', None)
|
db = kwargs.pop('using', None)
|
||||||
defaults = {
|
defaults = {
|
||||||
'form_class': forms.ModelChoiceField,
|
'form_class': forms.ModelChoiceField,
|
||||||
'queryset': self.rel.to._default_manager.using(db).complex_filter(self.rel.limit_choices_to).distinct(),
|
'queryset': self.rel.to._default_manager.using(db).complex_filter(self.rel.limit_choices_to),
|
||||||
'to_field_name': self.rel.field_name,
|
'to_field_name': self.rel.field_name,
|
||||||
}
|
}
|
||||||
defaults.update(kwargs)
|
defaults.update(kwargs)
|
||||||
|
@ -29,11 +29,6 @@ class Bar(models.Model):
|
|||||||
b = models.CharField(max_length=10)
|
b = models.CharField(max_length=10)
|
||||||
a = models.ForeignKey(Foo, default=get_foo)
|
a = models.ForeignKey(Foo, default=get_foo)
|
||||||
|
|
||||||
class Baz(models.Model):
|
|
||||||
a = models.CharField(max_length=5)
|
|
||||||
#Only Foos related to Bars starting with 'a'
|
|
||||||
foo = models.ForeignKey(Foo, limit_choices_to=models.Q(bar__b__startswith='a'))
|
|
||||||
|
|
||||||
class Whiz(models.Model):
|
class Whiz(models.Model):
|
||||||
CHOICES = (
|
CHOICES = (
|
||||||
('Group 1', (
|
('Group 1', (
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import re
|
|
||||||
|
|
||||||
from django import test
|
from django import test
|
||||||
from django import forms
|
from django import forms
|
||||||
@ -9,7 +8,7 @@ from django.db import models
|
|||||||
from django.db.models.fields.files import FieldFile
|
from django.db.models.fields.files import FieldFile
|
||||||
from django.utils import unittest
|
from django.utils import unittest
|
||||||
|
|
||||||
from models import Foo, Bar, Baz, Whiz, BigD, BigS, Image, BigInt, Post, NullBooleanModel, BooleanModel, Document
|
from models import Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post, NullBooleanModel, BooleanModel, Document
|
||||||
|
|
||||||
# If PIL available, do these tests.
|
# If PIL available, do these tests.
|
||||||
if Image:
|
if Image:
|
||||||
@ -96,10 +95,6 @@ class DecimalFieldTests(test.TestCase):
|
|||||||
# This should not crash. That counts as a win for our purposes.
|
# This should not crash. That counts as a win for our purposes.
|
||||||
Foo.objects.filter(d__gte=100000000000)
|
Foo.objects.filter(d__gte=100000000000)
|
||||||
|
|
||||||
class BazForm(forms.ModelForm):
|
|
||||||
class Meta:
|
|
||||||
model = Baz
|
|
||||||
|
|
||||||
class ForeignKeyTests(test.TestCase):
|
class ForeignKeyTests(test.TestCase):
|
||||||
def test_callable_default(self):
|
def test_callable_default(self):
|
||||||
"""Test the use of a lazy callable for ForeignKey.default"""
|
"""Test the use of a lazy callable for ForeignKey.default"""
|
||||||
@ -107,18 +102,6 @@ class ForeignKeyTests(test.TestCase):
|
|||||||
b = Bar.objects.create(b="bcd")
|
b = Bar.objects.create(b="bcd")
|
||||||
self.assertEqual(b.a, a)
|
self.assertEqual(b.a, a)
|
||||||
|
|
||||||
def test_distinct_choice_limit(self):
|
|
||||||
"""Doesn't make sense to offer the same ForeignKey multiple times in a form"""
|
|
||||||
a = Foo.objects.create(a='a', d=Decimal("-1"))
|
|
||||||
b = Foo.objects.create(a='b', d=Decimal("1"))
|
|
||||||
bar_a = Bar.objects.create(b='ah', a=a)
|
|
||||||
bar_b = Bar.objects.create(b='aha', a=a)
|
|
||||||
bar_b = Bar.objects.create(b='bla', a=b)
|
|
||||||
form = BazForm()
|
|
||||||
fk_field = str(form['foo'])
|
|
||||||
self.assertEqual(len(re.findall(r'value="%d"' % b.pk, fk_field)), 0)
|
|
||||||
self.assertEqual(len(re.findall(r'value="%d"' % a.pk, fk_field)), 1)
|
|
||||||
|
|
||||||
class DateTimeFieldTests(unittest.TestCase):
|
class DateTimeFieldTests(unittest.TestCase):
|
||||||
def test_datetimefield_to_python_usecs(self):
|
def test_datetimefield_to_python_usecs(self):
|
||||||
"""DateTimeField.to_python should support usecs"""
|
"""DateTimeField.to_python should support usecs"""
|
||||||
|
Loading…
Reference in New Issue
Block a user