Changeset 6940
- Timestamp:
- 12/17/07 05:59:53 (1 year ago)
- Files:
-
- django/trunk/django/newforms/models.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/newforms/models.py
r6917 r6940 150 150 Returns a dict containing the data in ``instance`` suitable for passing as 151 151 a Form's ``initial`` keyword argument. 152 152 153 153 ``fields`` is an optional list of field names. If provided, only the named 154 154 fields will be included in the returned dict. 155 155 156 156 ``exclude`` is an optional list of field names. If provided, the named 157 157 fields will be excluded from the returned dict, even if they are listed in … … 188 188 ``fields`` is an optional list of field names. If provided, only the named 189 189 fields will be included in the returned fields. 190 190 191 191 ``exclude`` is an optional list of field names. If provided, the named 192 192 fields will be excluded from the returned fields, even if they are listed … … 215 215 216 216 class ModelFormMetaclass(type): 217 def __new__(cls, name, bases, attrs): 218 # TODO: no way to specify formfield_callback yet, do we need one, or 219 # should it be a special case for the admin? 217 def __new__(cls, name, bases, attrs, 218 formfield_callback=lambda f: f.formfield()): 220 219 fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)] 221 220 fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter)) … … 254 253 if base_model and base_model is not opts.model: 255 254 raise ImproperlyConfigured('%s defines a different model than its parent.' % name) 256 model_fields = fields_for_model(opts.model, opts.fields, opts.exclude) 255 model_fields = fields_for_model(opts.model, opts.fields, 256 opts.exclude, formfield_callback) 257 257 # fields declared in base classes override fields from the model 258 258 model_fields.update(declared_fields)
