Fixed #6197 -- Added (optional) formfield_callback argument to ModelForms.__new__. Patch from guido@python.org.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6940 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-12-17 11:59:53 +00:00
parent b279b75c87
commit ec72071615
1 changed files with 7 additions and 7 deletions

View File

@ -214,9 +214,8 @@ class ModelFormOptions(object):
self.exclude = getattr(options, 'exclude', None) self.exclude = getattr(options, 'exclude', None)
class ModelFormMetaclass(type): class ModelFormMetaclass(type):
def __new__(cls, name, bases, attrs): def __new__(cls, name, bases, attrs,
# TODO: no way to specify formfield_callback yet, do we need one, or formfield_callback=lambda f: f.formfield()):
# should it be a special case for the admin?
fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)] fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)]
fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter)) fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter))
@ -253,7 +252,8 @@ class ModelFormMetaclass(type):
base_model = getattr(base_opts, 'model', None) base_model = getattr(base_opts, 'model', None)
if base_model and base_model is not opts.model: if base_model and base_model is not opts.model:
raise ImproperlyConfigured('%s defines a different model than its parent.' % name) raise ImproperlyConfigured('%s defines a different model than its parent.' % name)
model_fields = fields_for_model(opts.model, opts.fields, opts.exclude) model_fields = fields_for_model(opts.model, opts.fields,
opts.exclude, formfield_callback)
# fields declared in base classes override fields from the model # fields declared in base classes override fields from the model
model_fields.update(declared_fields) model_fields.update(declared_fields)
attrs['base_fields'] = model_fields attrs['base_fields'] = model_fields