# HG changeset patch
# Parent 1fd21f6a77e8dee636bd0edc66a4fbfbf8d35f7b
# User Rolando Espinoza La fuente <darkrho@gmail.com>
diff --git a/django/forms/models.py b/django/forms/models.py
a
|
b
|
def model_to_dict(instance, fields=None,
|
150 | 150 | data[f.name] = f.value_from_object(instance) |
151 | 151 | return data |
152 | 152 | |
153 | | def fields_for_model(model, fields=None, exclude=None, widgets=None, formfield_callback=lambda f, **kwargs: f.formfield(**kwargs)): |
| 153 | def fields_for_model(model, fields=None, exclude=None, widgets=None, formfield_callback=lambda f, **kwargs: f.formfield(**kwargs), fields_attrs={}): |
154 | 154 | """ |
155 | 155 | Returns a ``SortedDict`` containing form fields for the given model. |
156 | 156 | |
… |
… |
def fields_for_model(model, fields=None,
|
175 | 175 | kwargs = {'widget': widgets[f.name]} |
176 | 176 | else: |
177 | 177 | kwargs = {} |
| 178 | if fields_attrs and f.name in fields_attrs: |
| 179 | # @@@ prevent collision with widget |
| 180 | if 'widget' in fields_attrs[f.name]: |
| 181 | del fields_attrs[f.name]['widget'] |
| 182 | kwargs.update(fields_attrs[f.name]) |
178 | 183 | formfield = formfield_callback(f, **kwargs) |
179 | 184 | if formfield: |
180 | 185 | field_list.append((f.name, formfield)) |
… |
… |
class ModelFormOptions(object):
|
192 | 197 | def __init__(self, options=None): |
193 | 198 | self.model = getattr(options, 'model', None) |
194 | 199 | self.fields = getattr(options, 'fields', None) |
| 200 | self.fields_attrs = getattr(options, 'fields_attrs', None) |
195 | 201 | self.exclude = getattr(options, 'exclude', None) |
196 | 202 | self.widgets = getattr(options, 'widgets', None) |
197 | 203 | |
… |
… |
class ModelFormMetaclass(type):
|
217 | 223 | if opts.model: |
218 | 224 | # If a model is defined, extract form fields from it. |
219 | 225 | fields = fields_for_model(opts.model, opts.fields, |
220 | | opts.exclude, opts.widgets, formfield_callback) |
| 226 | opts.exclude, opts.widgets, formfield_callback, |
| 227 | opts.fields_attrs) |
221 | 228 | # Override default model fields with any custom declared ones |
222 | 229 | # (plus, include all the other declared fields). |
223 | 230 | fields.update(declared_fields) |