Skip to content

Commit c342c30

Browse files
committed
tests for #14082
.. but it seems it works in django trunk
1 parent e6306dc commit c342c30

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

tests/regressiontests/model_forms_regress/models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
from django.db import models
33
from django.core.exceptions import ValidationError
44

5+
from django.forms.models import ModelForm, ModelFormMetaclass
6+
7+
8+
class MyModelFormMetaclass(ModelFormMetaclass):
9+
run = 0
10+
def __new__(*args, **kwargs):
11+
MyModelFormMetaclass.run += 1
12+
return ModelFormMetaclass.__new__(*args, **kwargs)
13+
14+
class MyModelForm(ModelForm):
15+
__metaclass__ = MyModelFormMetaclass
16+
517

618
class Person(models.Model):
719
name = models.CharField(max_length=100)

tests/regressiontests/model_forms_regress/tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
from models import Person, RealPerson, Triple, FilePathModel, Article, \
1111
Publication, CustomFF, Author, Author1, Homepage, Document, Edition
1212

13+
from models import MyModelForm, MyModelFormMetaclass
14+
15+
16+
class TestModelFormFactory(TestCase):
17+
def test_modelform_factory_use_specific_model_form_metaclass(self):
18+
a = modelform_factory(Person, form=MyModelForm)
19+
x = a()
20+
self.failUnlessEqual(2, MyModelFormMetaclass.run)
21+
self.failUnlessEqual(MyModelFormMetaclass, type(type(x)))
22+
1323

1424
class ModelMultipleChoiceFieldTests(TestCase):
1525
def test_model_multiple_choice_number_of_queries(self):

0 commit comments

Comments
 (0)