Author: Alex
Date: 2011-01-25 21:52:52 -0600 (Tue, 25 Jan 2011)
New Revision: 15320
Modified:
django/branches/releases/1.2.X/django/db/models/base.py
django/branches/releases/1.2.X/tests/modeltests/model_inheritance/models.py
django/branches/releases/1.2.X/tests/modeltests/model_inheritance/tests.py
Log:
[1.2.X] Fixed #13206 -- call super().__init__() in Model.__init__ to allow
mixins to do things there. Backport of [15317].
Modified: django/branches/releases/1.2.X/django/db/models/base.py
===================================================================
--- django/branches/releases/1.2.X/django/db/models/base.py 2011-01-26
03:52:41 UTC (rev 15319)
+++ django/branches/releases/1.2.X/django/db/models/base.py 2011-01-26
03:52:52 UTC (rev 15320)
@@ -1,6 +1,7 @@
import types
import sys
from itertools import izip
+
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 import validators
@@ -359,6 +360,7 @@
pass
if kwargs:
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)
def __repr__(self):
Modified:
django/branches/releases/1.2.X/tests/modeltests/model_inheritance/models.py
===================================================================
--- django/branches/releases/1.2.X/tests/modeltests/model_inheritance/models.py
2011-01-26 03:52:41 UTC (rev 15319)
+++ django/branches/releases/1.2.X/tests/modeltests/model_inheritance/models.py
2011-01-26 03:52:52 UTC (rev 15320)
@@ -143,3 +143,11 @@
def __unicode__(self):
return self.content
+
+class Mixin(object):
+ def __init__(self):
+ self.other_attr = 1
+ super(Mixin, self).__init__()
+
+class MixinModel(models.Model, Mixin):
+ pass
Modified:
django/branches/releases/1.2.X/tests/modeltests/model_inheritance/tests.py
===================================================================
--- django/branches/releases/1.2.X/tests/modeltests/model_inheritance/tests.py
2011-01-26 03:52:41 UTC (rev 15319)
+++ django/branches/releases/1.2.X/tests/modeltests/model_inheritance/tests.py
2011-01-26 03:52:52 UTC (rev 15320)
@@ -6,7 +6,7 @@
from django.test import TestCase
from models import (Chef, CommonInfo, ItalianRestaurant, ParkingLot, Place,
- Post, Restaurant, Student, StudentWorker, Supplier, Worker)
+ Post, Restaurant, Student, StudentWorker, Supplier, Worker, MixinModel)
class ModelInheritanceTests(TestCase):
@@ -278,4 +278,6 @@
finally:
settings.DEBUG = old_DEBUG
-
+ def test_mixin_init(self):
+ m = MixinModel()
+ self.assertEqual(m.other_attr, 1)
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.