Ticket #11183: 11183.2.diff

File 11183.2.diff, 1.8 KB (added by Luke Plant, 15 years ago)

revised patch

  • django/forms/models.py

     
    923923        self.choice_cache = None
    924924        self.to_field_name = to_field_name
    925925
     926    def __deepcopy__(self, memo):
     927        result = super(ChoiceField, self).__deepcopy__(memo)
     928        # Need to force a new ModelChoiceIterator to be created, bug #11183
     929        result.queryset = result.queryset
     930        return result
     931
    926932    def _get_queryset(self):
    927933        return self._queryset
    928934
  • tests/regressiontests/model_forms_regress/tests.py

     
    22
    33from django import db
    44from django import forms
    5 from django.forms.models import modelform_factory
     5from django.forms.models import modelform_factory, ModelChoiceField
    66from django.conf import settings
    77from django.test import TestCase
    88
     
    203203        form = AuthorForm({'publication':u'', 'full_name':'John Doe'}, instance=author)
    204204        self.assert_(not form.is_valid())
    205205
     206
     207class ModelChoiceForm1(forms.Form):
     208    person = ModelChoiceField(Person.objects.all())
     209
     210
     211class TestTicket11183(TestCase):
     212    def test_11183(self):
     213        form1 = ModelChoiceForm1()
     214        field1 = form1.fields['person']
     215        self.assert_(field1 is not ModelChoiceForm1.base_fields['person']) # sanity check
     216        # To allow us to change the queryset of field1.widget.choices correctly,
     217        # without affecting other forms, the following must hold:
     218        self.assert_(field1.widget.choices.field is not ModelChoiceForm1.base_fields['person'])
Back to Top