Index: models.py =================================================================== --- models.py (revision 13431) +++ models.py (working copy) @@ -150,7 +150,7 @@ data[f.name] = f.value_from_object(instance) return data -def fields_for_model(model, fields=None, exclude=None, widgets=None, formfield_callback=lambda f, **kwargs: f.formfield(**kwargs)): +def fields_for_model(model, fields=None, exclude=None, widgets=None, formfield_callback=None): """ Returns a ``SortedDict`` containing form fields for the given model. @@ -175,6 +175,10 @@ kwargs = {'widget': widgets[f.name]} else: kwargs = {} + + if not formfield_callback: + formfield_callback = lambda f, **kwargs: f.formfield(**kwargs) + formfield = formfield_callback(f, **kwargs) if formfield: field_list.append((f.name, formfield)) @@ -198,8 +202,8 @@ class ModelFormMetaclass(type): def __new__(cls, name, bases, attrs): - formfield_callback = attrs.pop('formfield_callback', - lambda f, **kwargs: f.formfield(**kwargs)) + formfield_callback = attrs.pop('formfield_callback', None) + try: parents = [b for b in bases if issubclass(b, ModelForm)] except NameError: @@ -375,8 +379,7 @@ class ModelForm(BaseModelForm): __metaclass__ = ModelFormMetaclass -def modelform_factory(model, form=ModelForm, fields=None, exclude=None, - formfield_callback=lambda f: f.formfield()): +def modelform_factory(model, form=ModelForm, fields=None, exclude=None, formfield_callback=None): # Create the inner Meta class. FIXME: ideally, we should be able to # construct a ModelForm without creating and passing in a temporary # inner class. @@ -658,7 +661,7 @@ form.fields[self._pk_field.name] = ModelChoiceField(qs, initial=pk_value, required=False, widget=HiddenInput) super(BaseModelFormSet, self).add_fields(form, index) -def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(), +def modelformset_factory(model, form=ModelForm, formfield_callback=None, formset=BaseModelFormSet, extra=1, can_delete=False, can_order=False, max_num=None, fields=None, exclude=None): @@ -813,7 +816,7 @@ formset=BaseInlineFormSet, fk_name=None, fields=None, exclude=None, extra=3, can_order=False, can_delete=True, max_num=None, - formfield_callback=lambda f: f.formfield()): + formfield_callback=None): """ Returns an ``InlineFormSet`` for the given kwargs.