Ticket #3247: disable_formfield_for_hidden_fields.diff

File disable_formfield_for_hidden_fields.diff, 1.7 KB (added by mssnlayam@…, 18 years ago)
  • models.py

     
    4545    opts = model._meta
    4646    field_list = []
    4747    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))
    5152    fields = SortedDictFromList(field_list)
    5253    return type(opts.object_name + 'Form', (form,), {'fields': fields, '_model': model, 'create': create})
    5354
     
    6162    opts = model._meta
    6263    field_list = []
    6364    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))
    6870    fields = SortedDictFromList(field_list)
    6971    return type(opts.object_name + 'InstanceForm', (form,),
    7072        {'fields': fields, '_model': model, 'apply_changes': make_apply_changes(opts, instance)})
    7173
    7274def form_for_fields(field_list):
    7375    "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])
    7577    return type('FormForFields', (BaseForm,), {'fields': fields})
Back to Top