Ticket #4967: newforms_models_defaults.diff
File newforms_models_defaults.diff, 1.3 KB (added by , 17 years ago) |
---|
-
newforms/models.py
60 60 return save_instance(self, instance, fields, fail_message, commit) 61 61 return save 62 62 63 def form_for_model(model, form=BaseForm, fields=None, formfield_callback=lambda f : f.formfield()):63 def form_for_model(model, form=BaseForm, fields=None, formfield_callback=lambda f, **kwargs: f.formfield(**kwargs)): 64 64 """ 65 65 Returns a Form class for the given Django model class. 66 66 … … 70 70 determining the formfield for a given database field. It's a callable that 71 71 takes a database Field instance and returns a form Field instance. 72 72 """ 73 from django.db import models 73 74 opts = model._meta 74 75 field_list = [] 75 76 for f in opts.fields + opts.many_to_many: … … 77 78 continue 78 79 if fields and not f.name in fields: 79 80 continue 80 formfield = formfield_callback(f) 81 if f.default==models.fields.NOT_PROVIDED: 82 value=None 83 else: 84 value=f.default 85 formfield = formfield_callback(f, initial=value) 81 86 if formfield: 82 87 field_list.append((f.name, formfield)) 83 88 base_fields = SortedDictFromList(field_list)