Ticket #5126: ticket5126.diff
File ticket5126.diff, 1.5 KB (added by , 17 years ago) |
---|
-
django/newforms/models.py
54 54 form.save_m2m = save_m2m 55 55 return instance 56 56 57 def make_model_init(form, fields): 58 """Returns the __init__() method for a Form.""" 59 def __init__(self, instance=None, **kwargs): 60 if instance: 61 opts = instance.__class__._meta 62 initial = kwargs.setdefault('initial', {}) 63 for f in opts.fields: 64 if not f.editable or f.name in initial: 65 continue 66 if fields and f.name not in fields: 67 continue 68 initial[f.name] = f.value_from_object(instance) 69 form.__init__(self, **kwargs) 70 return __init__ 71 57 72 def make_model_save(model, fields, fail_message): 58 73 "Returns the save() method for a Form." 59 74 def save(self, commit=True): … … 88 103 field_list.append((f.name, formfield)) 89 104 base_fields = SortedDictFromList(field_list) 90 105 return type(opts.object_name + 'Form', (form,), 91 {'base_fields': base_fields, '_model': model, 'save': make_model_save(model, fields, 'created')}) 106 {'base_fields': base_fields, '_model': model, '__init__': make_model_init(form, fields), 107 'save': make_model_save(model, fields, 'created')}) 92 108 93 109 def form_for_instance(instance, form=BaseForm, fields=None, formfield_callback=lambda f, **kwargs: f.formfield(**kwargs)): 94 110 """