Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
399a8db3
Kaydet (Commit)
399a8db3
authored
Eki 14, 2017
tarafından
k
Kaydeden (comit)
Tim Graham
Eki 14, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28695 -- Allowed models to use __init_subclass__().
üst
9dd40597
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
3 deletions
+22
-3
base.py
django/db/models/base.py
+2
-2
2.1.txt
docs/releases/2.1.txt
+1
-1
tests.py
tests/model_inheritance/tests.py
+19
-0
No files found.
django/db/models/base.py
Dosyayı görüntüle @
399a8db3
...
...
@@ -60,7 +60,7 @@ def subclass_exception(name, bases, module, attached_to):
class
ModelBase
(
type
):
"""Metaclass for all models."""
def
__new__
(
cls
,
name
,
bases
,
attrs
):
def
__new__
(
cls
,
name
,
bases
,
attrs
,
**
kwargs
):
super_new
=
super
()
.
__new__
# Also ensure initialization is only performed for subclasses of Model
...
...
@@ -75,7 +75,7 @@ class ModelBase(type):
classcell
=
attrs
.
pop
(
'__classcell__'
,
None
)
if
classcell
is
not
None
:
new_attrs
[
'__classcell__'
]
=
classcell
new_class
=
super_new
(
cls
,
name
,
bases
,
new_attrs
)
new_class
=
super_new
(
cls
,
name
,
bases
,
new_attrs
,
**
kwargs
)
attr_meta
=
attrs
.
pop
(
'Meta'
,
None
)
abstract
=
getattr
(
attr_meta
,
'abstract'
,
False
)
if
not
attr_meta
:
...
...
docs/releases/2.1.txt
Dosyayı görüntüle @
399a8db3
...
...
@@ -153,7 +153,7 @@ Migrations
Models
~~~~~~
*
..
.
*
Models can now use ``__init_subclass__()`` from :pep:`487`
.
Requests and Responses
~~~~~~~~~~~~~~~~~~~~~~
...
...
tests/model_inheritance/tests.py
Dosyayı görüntüle @
399a8db3
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment