Ticket #5634: django.newforms.models.py.diff
File django.newforms.models.py.diff, 1.4 KB (added by , 17 years ago) |
---|
-
django/newforms/models.py
66 66 return save_instance(self, instance, fields, fail_message, commit) 67 67 return save 68 68 69 def form_for_model(model, form=BaseForm, fields=None, formfield_callback=lambda f: f.formfield()):69 def form_for_model(model, form=BaseForm, fields=None, queryset=None, formfield_callback=lambda f, **kwargs: f.formfield(**kwargs)): 70 70 """ 71 71 Returns a Form class for the given Django model class. 72 72 … … 76 76 determining the formfield for a given database field. It's a callable that 77 77 takes a database Field instance and returns a form Field instance. 78 78 """ 79 from django.db.models.fields.related import ManyToManyField 79 80 opts = model._meta 80 81 field_list = [] 81 82 for f in opts.fields + opts.many_to_many: … … 83 84 continue 84 85 if fields and not f.name in fields: 85 86 continue 86 formfield = formfield_callback(f) 87 if isinstance(f, ManyToManyField) and queryset is not None: 88 formfield = formfield_callback(f, queryset=queryset) 89 else: 90 formfield = formfield_callback(f) 87 91 if formfield: 88 92 field_list.append((f.name, formfield)) 89 93 base_fields = SortedDictFromList(field_list)