Ticket #15127: choicefield-deepcopy-v1.diff
File choicefield-deepcopy-v1.diff, 2.0 KB (added by , 13 years ago) |
---|
-
django/forms/fields.py
695 695 return True 696 696 return False 697 697 698 def __deepcopy__(self, memo): 699 result = super(ChoiceField, self).__deepcopy__(memo) 700 result._choices = copy.copy(self._choices) 701 return result 702 703 698 704 class TypedChoiceField(ChoiceField): 699 705 def __init__(self, *args, **kwargs): 700 706 self.coerce = kwargs.pop('coerce', lambda val: val) -
tests/regressiontests/forms/tests/forms.py
771 771 f = Person(name_max_length=None) 772 772 self.assertEqual(f['first_name'].field.max_length, f['last_name'].field.max_length, (30, 30)) 773 773 774 class Person(Form): 775 first_name = CharField(required=False) 776 last_name = CharField(required=False) 777 gender = ChoiceField(choices=(('f', 'Female'), ('m', 'Male'))) 778 779 def __init__(self, allow_unspec_gender=False, *args, **kwargs): 780 super(Person, self).__init__(*args, **kwargs) 781 782 if allow_unspec_gender: 783 self.fields['gender'].choices += (('u', 'Unspecified'),) 784 785 f = Person() 786 self.assertEqual(len(f['gender'].field.choices), 2) 787 f = Person(allow_unspec_gender=True) 788 self.assertEqual(len(f['gender'].field.choices), 3) 789 self.assertEqual(f['gender'].field.choices[2], ('u', 'Unspecified')) 790 f = Person() 791 self.assertEqual(len(f['gender'].field.choices), 2) 792 793 794 774 795 def test_hidden_widget(self): 775 796 # HiddenInput widgets are displayed differently in the as_table(), as_ul()) 776 797 # and as_p() output of a Form -- their verbose names are not displayed, and a