Ticket #3268: models.diff

File models.diff, 1.4 KB (added by ryan.moe@…, 18 years ago)
  • models.py

     
    44"""
    55
    66from forms import BaseForm, DeclarativeFieldsMetaclass, SortedDictFromList
     7from fields import ChoiceField
     8from django.utils.text import capfirst
    79
    810__all__ = ('save_instance', 'form_for_model', 'form_for_instance', 'form_for_fields')
    911
     
    5658    opts = model._meta
    5759    field_list = []
    5860    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()
    6065        if formfield:
    6166            field_list.append((f.name, formfield))
    6267    fields = SortedDictFromList(field_list)
     
    7378    field_list = []
    7479    for f in opts.fields + opts.many_to_many:
    7580        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)
    7785        if formfield:
    7886            field_list.append((f.name, formfield))
    7987    fields = SortedDictFromList(field_list)
Back to Top