diff --git a/django/forms/models.py b/django/forms/models.py
index ecfdc92..b34f4d0 100644
a
|
b
|
def modelform_factory(model, form=ModelForm, fields=None, exclude=None,
|
396 | 396 | 'formfield_callback': formfield_callback |
397 | 397 | } |
398 | 398 | |
399 | | return ModelFormMetaclass(class_name, (form,), form_class_attrs) |
| 399 | form_metaclass = ModelFormMetaclass |
| 400 | |
| 401 | if issubclass(form, BaseModelForm) and hasattr(form, '__metaclass__'): |
| 402 | form_metaclass = form.__metaclass__ |
| 403 | |
| 404 | return form_metaclass(class_name, (form,), form_class_attrs) |
400 | 405 | |
401 | 406 | |
402 | 407 | # ModelFormSets ############################################################## |
diff --git a/tests/regressiontests/model_forms_regress/tests.py b/tests/regressiontests/model_forms_regress/tests.py
index f536001..9817858 100644
a
|
b
|
from django import forms
|
4 | 4 | from django.core.exceptions import FieldError, ValidationError |
5 | 5 | from django.core.files.uploadedfile import SimpleUploadedFile |
6 | 6 | from django.forms.models import (modelform_factory, ModelChoiceField, |
7 | | fields_for_model, construct_instance) |
| 7 | fields_for_model, construct_instance, ModelFormMetaclass) |
8 | 8 | from django.utils import unittest |
9 | 9 | from django.test import TestCase |
10 | 10 | |
… |
… |
class EmptyFieldsTestCase(TestCase):
|
460 | 460 | self.assertTrue(form.is_valid()) |
461 | 461 | instance = construct_instance(form, Person(), fields=()) |
462 | 462 | self.assertEqual(instance.name, '') |
| 463 | |
| 464 | |
| 465 | class CustomMetaclass(ModelFormMetaclass): |
| 466 | def __new__(cls, name, bases, attrs): |
| 467 | new = super(CustomMetaclass, cls).__new__(cls, name, bases, attrs) |
| 468 | new.base_fields = {} |
| 469 | return new |
| 470 | |
| 471 | class CustomMetaclassForm(forms.ModelForm): |
| 472 | __metaclass__ = CustomMetaclass |
| 473 | |
| 474 | |
| 475 | class CustomMetaclassTestCase(TestCase): |
| 476 | def test_modelform_factory_metaclass(self): |
| 477 | new_cls = modelform_factory(Person, form=CustomMetaclassForm) |
| 478 | self.assertEqual(new_cls.base_fields, {}) |