Ticket #10431: lsaffre_20090307.diff
File lsaffre_20090307.diff, 1.9 KB (added by , 16 years ago) |
---|
-
django/forms/models.py
143 143 Returns a ``SortedDict`` containing form fields for the given model. 144 144 145 145 ``fields`` is an optional list of field names. If provided, only the named 146 fields will be included in the returned fields. 146 fields will be included in the returned fields. 147 147 148 148 ``exclude`` is an optional list of field names. If provided, the named 149 149 fields will be excluded from the returned fields, even if they are listed 150 150 in the ``fields`` argument. 151 152 If ``fields`` is provided, the returned list will be in that order, 153 otherwise as defined in the Model. 151 154 """ 152 # TODO: if fields is provided, it would be nice to return fields in that order155 # 153 156 field_list = [] 154 157 opts = model._meta 155 for f in opts.fields + opts.many_to_many: 158 if fields: 159 def search(name): 160 for f in opts.fields + opts.many_to_many: 161 if name == f.name: 162 return f 163 model_fields = [] 164 for fn in fields: 165 f = search(fn) 166 if f: 167 model_fields.append(f) 168 # TODO: Otherwise raise an exception here? Which one? 169 else: 170 model_fields = opts.fields + opts.many_to_many 171 for f in model_fields: 156 172 if not f.editable: 157 173 continue 158 if fields and not f.name in fields:159 continue160 174 if exclude and f.name in exclude: 161 175 continue 162 176 formfield = formfield_callback(f) … … 164 178 field_list.append((f.name, formfield)) 165 179 return SortedDict(field_list) 166 180 181 167 182 class ModelFormOptions(object): 168 183 def __init__(self, options=None): 169 184 self.model = getattr(options, 'model', None)