mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
[1.1.X] Fixed #11183 - BaseForm init leaves pointers pointing back to base_fields
Thanks to margieroginski for the report Backport of [12733] from trunk git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12736 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f13b17ad15
commit
89c2639323
@ -952,6 +952,12 @@ class ModelChoiceField(ChoiceField):
|
|||||||
self.choice_cache = None
|
self.choice_cache = None
|
||||||
self.to_field_name = to_field_name
|
self.to_field_name = to_field_name
|
||||||
|
|
||||||
|
def __deepcopy__(self, memo):
|
||||||
|
result = super(ChoiceField, self).__deepcopy__(memo)
|
||||||
|
# Need to force a new ModelChoiceIterator to be created, bug #11183
|
||||||
|
result.queryset = result.queryset
|
||||||
|
return result
|
||||||
|
|
||||||
def _get_queryset(self):
|
def _get_queryset(self):
|
||||||
return self._queryset
|
return self._queryset
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ from datetime import date
|
|||||||
|
|
||||||
from django import db
|
from django import db
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.forms.models import modelform_factory
|
from django.forms.models import modelform_factory, ModelChoiceField
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
@ -107,3 +107,17 @@ class ModelClassTests(TestCase):
|
|||||||
class NoModelModelForm(forms.ModelForm):
|
class NoModelModelForm(forms.ModelForm):
|
||||||
pass
|
pass
|
||||||
self.assertRaises(ValueError, NoModelModelForm)
|
self.assertRaises(ValueError, NoModelModelForm)
|
||||||
|
|
||||||
|
|
||||||
|
class ModelChoiceForm(forms.Form):
|
||||||
|
person = ModelChoiceField(Person.objects.all())
|
||||||
|
|
||||||
|
|
||||||
|
class TestTicket11183(TestCase):
|
||||||
|
def test_11183(self):
|
||||||
|
form1 = ModelChoiceForm()
|
||||||
|
field1 = form1.fields['person']
|
||||||
|
# To allow the widget to change the queryset of field1.widget.choices correctly,
|
||||||
|
# without affecting other forms, the following must hold:
|
||||||
|
self.assert_(field1 is not ModelChoiceForm.base_fields['person'])
|
||||||
|
self.assert_(field1.widget.choices.field is field1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user