Ticket #3268: models.diff
File models.diff, 1.4 KB (added by , 18 years ago) |
---|
-
models.py
4 4 """ 5 5 6 6 from forms import BaseForm, DeclarativeFieldsMetaclass, SortedDictFromList 7 from fields import ChoiceField 8 from django.utils.text import capfirst 7 9 8 10 __all__ = ('save_instance', 'form_for_model', 'form_for_instance', 'form_for_fields') 9 11 … … 56 58 opts = model._meta 57 59 field_list = [] 58 60 for f in opts.fields + opts.many_to_many: 59 formfield = f.formfield() 61 if f.choices: 62 formfield = ChoiceField(required=not f.blank, label=capfirst(f.verbose_name), choices=f.choices) 63 else: 64 formfield = f.formfield() 60 65 if formfield: 61 66 field_list.append((f.name, formfield)) 62 67 fields = SortedDictFromList(field_list) … … 73 78 field_list = [] 74 79 for f in opts.fields + opts.many_to_many: 75 80 current_value = f.value_from_object(instance) 76 formfield = f.formfield(initial=current_value) 81 if f.choices: 82 formfield = ChoiceField(required=not f.blank, label=capfirst(f.verbose_name), choices=f.choices, initial=current_value) 83 else: 84 formfield = f.formfield(initial=current_value) 77 85 if formfield: 78 86 field_list.append((f.name, formfield)) 79 87 fields = SortedDictFromList(field_list)