Ticket #6197: models.diff

File models.diff, 1.3 KB (added by guido@…, 16 years ago)

patch for newforms/models.py

  • models.py

     
    214214        self.exclude = getattr(options, 'exclude', None)
    215215
    216216class 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()):
    220219        fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)]
    221220        fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter))
    222221
     
    253252                base_model = getattr(base_opts, 'model', None)
    254253                if base_model is not None:
    255254                    raise ImproperlyConfigured('%s defines more than one model.' % name)
    256             model_fields = fields_for_model(opts.model, opts.fields, opts.exclude)
     255            model_fields = fields_for_model(opts.model, opts.fields, opts.exclude,
     256                                            formfields_callback)
    257257            # fields declared in base classes override fields from the model
    258258            model_fields.update(declared_fields)
    259259            attrs['base_fields'] = model_fields
Back to Top