mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
Fixed #28695 -- Allowed models to use __init_subclass__().
This commit is contained in:
parent
9dd405973c
commit
399a8db33b
3 changed files with 22 additions and 3 deletions
|
@ -1,9 +1,11 @@
|
|||
import unittest
|
||||
from operator import attrgetter
|
||||
|
||||
from django.core.exceptions import FieldError, ValidationError
|
||||
from django.db import connection, models
|
||||
from django.test import SimpleTestCase, TestCase
|
||||
from django.test.utils import CaptureQueriesContext, isolate_apps
|
||||
from django.utils.version import PY36
|
||||
|
||||
from .models import (
|
||||
Base, Chef, CommonInfo, GrandChild, GrandParent, ItalianRestaurant,
|
||||
|
@ -156,6 +158,23 @@ class ModelInheritanceTests(TestCase):
|
|||
|
||||
self.assertIs(C._meta.parents[A], C._meta.get_field('a'))
|
||||
|
||||
@unittest.skipUnless(PY36, 'init_subclass is new in Python 3.6')
|
||||
@isolate_apps('model_inheritance')
|
||||
def test_init_subclass(self):
|
||||
saved_kwargs = {}
|
||||
|
||||
class A:
|
||||
def __init_subclass__(cls, **kwargs):
|
||||
super().__init_subclass__()
|
||||
saved_kwargs.update(kwargs)
|
||||
|
||||
kwargs = {'x': 1, 'y': 2, 'z': 3}
|
||||
|
||||
class B(A, models.Model, **kwargs):
|
||||
pass
|
||||
|
||||
self.assertEqual(saved_kwargs, kwargs)
|
||||
|
||||
|
||||
class ModelInheritanceDataTests(TestCase):
|
||||
@classmethod
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue