Code

Ticket #3268: models.diff

File models.diff, 1.4 KB (added by ryan.moe@…, 7 years ago)
Line 
1Index: models.py
2===================================================================
3--- models.py   (revision 4358)
4+++ models.py   (working copy)
5@@ -4,6 +4,8 @@
6 """
7 
8 from forms import BaseForm, DeclarativeFieldsMetaclass, SortedDictFromList
9+from fields import ChoiceField
10+from django.utils.text import capfirst
11 
12 __all__ = ('save_instance', 'form_for_model', 'form_for_instance', 'form_for_fields')
13 
14@@ -56,7 +58,10 @@
15     opts = model._meta
16     field_list = []
17     for f in opts.fields + opts.many_to_many:
18-        formfield = f.formfield()
19+        if f.choices:
20+            formfield = ChoiceField(required=not f.blank, label=capfirst(f.verbose_name), choices=f.choices)
21+        else:
22+            formfield = f.formfield()
23         if formfield:
24             field_list.append((f.name, formfield))
25     fields = SortedDictFromList(field_list)
26@@ -73,7 +78,10 @@
27     field_list = []
28     for f in opts.fields + opts.many_to_many:
29         current_value = f.value_from_object(instance)
30-        formfield = f.formfield(initial=current_value)
31+        if f.choices:
32+            formfield = ChoiceField(required=not f.blank, label=capfirst(f.verbose_name), choices=f.choices, initial=current_value)
33+        else:
34+            formfield = f.formfield(initial=current_value)
35         if formfield:
36             field_list.append((f.name, formfield))
37     fields = SortedDictFromList(field_list)