Optimize NewBase test of six.with_metaclass() for Django 1.5+

This commit is contained in:
Diederik van der Boor
2014-02-13 10:43:33 +01:00
parent 96ac22b55f
commit 4be6d42fad
+4 -1
View File
@@ -7,6 +7,7 @@ from __future__ import absolute_import
import sys import sys
import inspect import inspect
import django
from django.db import models from django.db import models
from django.db.models.base import ModelBase from django.db.models.base import ModelBase
from django.db.models.manager import ManagerDescriptor from django.db.models.manager import ManagerDescriptor
@@ -55,8 +56,10 @@ class PolymorphicModelBase(ModelBase):
#print; print '###', model_name, '- bases:', bases #print; print '###', model_name, '- bases:', bases
# Workaround compatibility issue with six.with_metaclass() and custom Django model metaclasses: # 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': if not attrs and model_name == 'NewBase':
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['__module__'] = 'django.utils.six'
attrs['Meta'] = type('Meta', (), {'abstract': True}) attrs['Meta'] = type('Meta', (), {'abstract': True})
return super(PolymorphicModelBase, self).__new__(self, model_name, bases, attrs) return super(PolymorphicModelBase, self).__new__(self, model_name, bases, attrs)