Ticket #13095: ticket13095_r13294.diff
File ticket13095_r13294.diff, 3.6 KB (added by , 15 years ago) |
---|
-
django/forms/models.py
376 376 __metaclass__ = ModelFormMetaclass 377 377 378 378 def modelform_factory(model, form=ModelForm, fields=None, exclude=None, 379 formfield_callback=lambda f : f.formfield()):379 formfield_callback=lambda f, **kwargs: f.formfield(**kwargs)): 380 380 # Create the inner Meta class. FIXME: ideally, we should be able to 381 381 # construct a ModelForm without creating and passing in a temporary 382 382 # inner class. … … 658 658 form.fields[self._pk_field.name] = ModelChoiceField(qs, initial=pk_value, required=False, widget=HiddenInput) 659 659 super(BaseModelFormSet, self).add_fields(form, index) 660 660 661 def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f : f.formfield(),661 def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f, **kwargs: f.formfield(**kwargs), 662 662 formset=BaseModelFormSet, 663 663 extra=1, can_delete=False, can_order=False, 664 664 max_num=None, fields=None, exclude=None): … … 813 813 formset=BaseInlineFormSet, fk_name=None, 814 814 fields=None, exclude=None, 815 815 extra=3, can_order=False, can_delete=True, max_num=None, 816 formfield_callback=lambda f : f.formfield()):816 formfield_callback=lambda f, **kwargs: f.formfield(**kwargs)): 817 817 """ 818 818 Returns an ``InlineFormSet`` for the given kwargs. 819 819 -
tests/regressiontests/forms/models.py
56 56 def __unicode__(self): 57 57 return u'%s' % self.name 58 58 59 class ParentModel(models.Model): 60 name = models.CharField(max_length=10) 61 62 class ForeignKeyModel(models.Model): 63 name = models.CharField(max_length=10) 64 parent = models.ForeignKey(ParentModel) 65 59 66 class TestTicket12510(TestCase): 60 67 ''' It is not necessary to generate choices for ModelChoiceField (regression test for #12510). ''' 61 68 def setUp(self): -
tests/regressiontests/forms/regressions.py
102 102 >>> f.as_table() 103 103 u'<tr><td colspan="2"><ul class="errorlist"><li>(Hidden field data) This field is required.</li></ul><input type="hidden" name="data" id="id_data" /></td></tr>' 104 104 105 Ticket #13095 : modelformset_factory, modelform_factory, and formset_factory didn't seem to handle Meta options well. 106 107 >>> from django import forms 108 >>> from regressiontests.forms import models 109 >>> class ForeignKeyModelForm(forms.ModelForm): 110 ... class Meta: 111 ... model = models.ForeignKeyModel 112 ... widgets = dict(name=forms.HiddenInput()) 113 ... 114 >>> _ = forms.models.modelform_factory(models.ForeignKeyModel, form=ForeignKeyModelForm)() # just need to check instantiation doesn't raise 115 >>> _ = forms.models.modelformset_factory(models.ForeignKeyModel, form=ForeignKeyModelForm)() 116 >>> _ = forms.models.inlineformset_factory(models.ParentModel, models.ForeignKeyModel, form=ForeignKeyModelForm)() 117 105 118 ################################################### 106 119 # Tests for XSS vulnerabilities in error messages # 107 120 ###################################################