Ticket #3247: disable_formfield_for_hidden_fields.diff
File disable_formfield_for_hidden_fields.diff, 1.7 KB (added by , 18 years ago) |
---|
-
models.py
45 45 opts = model._meta 46 46 field_list = [] 47 47 for f in opts.fields + opts.many_to_many: 48 formfield = f.formfield() 49 if formfield: 50 field_list.append((f.name, formfield)) 48 if f.editable: 49 formfield = f.formfield() 50 if formfield: 51 field_list.append((f.name, formfield)) 51 52 fields = SortedDictFromList(field_list) 52 53 return type(opts.object_name + 'Form', (form,), {'fields': fields, '_model': model, 'create': create}) 53 54 … … 61 62 opts = model._meta 62 63 field_list = [] 63 64 for f in opts.fields + opts.many_to_many: 64 current_value = f.value_from_object(instance) 65 formfield = f.formfield(initial=current_value) 66 if formfield: 67 field_list.append((f.name, formfield)) 65 if f.editable: 66 current_value = f.value_from_object(instance) 67 formfield = f.formfield(initial=current_value) 68 if formfield: 69 field_list.append((f.name, formfield)) 68 70 fields = SortedDictFromList(field_list) 69 71 return type(opts.object_name + 'InstanceForm', (form,), 70 72 {'fields': fields, '_model': model, 'apply_changes': make_apply_changes(opts, instance)}) 71 73 72 74 def form_for_fields(field_list): 73 75 "Returns a Form class for the given list of Django database field instances." 74 fields = SortedDictFromList([(f.name, f.formfield()) for f in field_list ])76 fields = SortedDictFromList([(f.name, f.formfield()) for f in field_list if f.editable]) 75 77 return type('FormForFields', (BaseForm,), {'fields': fields})