mirror of
https://github.com/django/django.git
synced 2025-07-05 02:09:13 +00:00
[1.2.X] Fixed #13206 -- call super().__init__() in Model.__init__ to allow mixins to do things there. Backport of [15317].
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15320 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
4cee764a46
commit
c4b0878b43
@ -1,6 +1,7 @@
|
|||||||
import types
|
import types
|
||||||
import sys
|
import sys
|
||||||
from itertools import izip
|
from itertools import izip
|
||||||
|
|
||||||
import django.db.models.manager # Imported to register signal handler.
|
import django.db.models.manager # Imported to register signal handler.
|
||||||
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, FieldError, ValidationError, NON_FIELD_ERRORS
|
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, FieldError, ValidationError, NON_FIELD_ERRORS
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
@ -359,6 +360,7 @@ class Model(object):
|
|||||||
pass
|
pass
|
||||||
if kwargs:
|
if kwargs:
|
||||||
raise TypeError("'%s' is an invalid keyword argument for this function" % kwargs.keys()[0])
|
raise TypeError("'%s' is an invalid keyword argument for this function" % kwargs.keys()[0])
|
||||||
|
super(Model, self).__init__()
|
||||||
signals.post_init.send(sender=self.__class__, instance=self)
|
signals.post_init.send(sender=self.__class__, instance=self)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -143,3 +143,11 @@ class Copy(NamedURL):
|
|||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.content
|
return self.content
|
||||||
|
|
||||||
|
class Mixin(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.other_attr = 1
|
||||||
|
super(Mixin, self).__init__()
|
||||||
|
|
||||||
|
class MixinModel(models.Model, Mixin):
|
||||||
|
pass
|
||||||
|
@ -6,7 +6,7 @@ from django.db import connection
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from models import (Chef, CommonInfo, ItalianRestaurant, ParkingLot, Place,
|
from models import (Chef, CommonInfo, ItalianRestaurant, ParkingLot, Place,
|
||||||
Post, Restaurant, Student, StudentWorker, Supplier, Worker)
|
Post, Restaurant, Student, StudentWorker, Supplier, Worker, MixinModel)
|
||||||
|
|
||||||
|
|
||||||
class ModelInheritanceTests(TestCase):
|
class ModelInheritanceTests(TestCase):
|
||||||
@ -278,4 +278,6 @@ class ModelInheritanceTests(TestCase):
|
|||||||
finally:
|
finally:
|
||||||
settings.DEBUG = old_DEBUG
|
settings.DEBUG = old_DEBUG
|
||||||
|
|
||||||
|
def test_mixin_init(self):
|
||||||
|
m = MixinModel()
|
||||||
|
self.assertEqual(m.other_attr, 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user