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

fix_request_path_info
Diederik van der Boor 2014-02-13 10:43:33 +01:00
parent 96ac22b55f
commit 4be6d42fad
1 changed files with 6 additions and 3 deletions

View File

@ -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,8 +56,10 @@ 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':
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)