From 4be6d42fad60c3e97e4d37f3fc9125d623468908 Mon Sep 17 00:00:00 2001 From: Diederik van der Boor Date: Thu, 13 Feb 2014 10:43:33 +0100 Subject: [PATCH] Optimize NewBase test of six.with_metaclass() for Django 1.5+ --- polymorphic/base.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/polymorphic/base.py b/polymorphic/base.py index 95a124e..ac0950c 100644 --- a/polymorphic/base.py +++ b/polymorphic/base.py @@ -7,6 +7,7 @@ from __future__ import absolute_import import sys import inspect +import django from django.db import models from django.db.models.base import ModelBase from django.db.models.manager import ManagerDescriptor @@ -55,10 +56,12 @@ class PolymorphicModelBase(ModelBase): #print; print '###', model_name, '- bases:', bases # Workaround compatibility issue with six.with_metaclass() and custom Django model metaclasses: - # Let Django fully ignore the class which is inserted in between. if not attrs and model_name == 'NewBase': - attrs['__module__'] = 'django.utils.six' - attrs['Meta'] = type('Meta', (), {'abstract': True}) + if django.VERSION < (1,5): + # Let Django fully ignore the class which is inserted in between. + # Django 1.5 fixed this, see https://code.djangoproject.com/ticket/19688 + attrs['__module__'] = 'django.utils.six' + attrs['Meta'] = type('Meta', (), {'abstract': True}) return super(PolymorphicModelBase, self).__new__(self, model_name, bases, attrs) # create new model