Django 1.7 upgrades
parent
e84a2072fc
commit
734752c2e7
|
|
@ -19,6 +19,7 @@ from django.utils.http import urlencode
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Django 1.6 implements this
|
# Django 1.6 implements this
|
||||||
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
|
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
|
||||||
|
|
@ -280,7 +281,10 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||||
Expose the custom URLs for the subclasses and the URL resolver.
|
Expose the custom URLs for the subclasses and the URL resolver.
|
||||||
"""
|
"""
|
||||||
urls = super(PolymorphicParentModelAdmin, self).get_urls()
|
urls = super(PolymorphicParentModelAdmin, self).get_urls()
|
||||||
info = self.model._meta.app_label, self.model._meta.module_name
|
try:
|
||||||
|
info = self.model._meta.app_label, self.model._meta.model_name
|
||||||
|
except:
|
||||||
|
info = self.model._meta.app_label, self.model._meta.module_name
|
||||||
|
|
||||||
# Patch the change URL so it's not a big catch-all; allowing all custom URLs to be added to the end.
|
# Patch the change URL so it's not a big catch-all; allowing all custom URLs to be added to the end.
|
||||||
# The url needs to be recreated, patching url.regex is not an option Django 1.4's LocaleRegexProvider changed it.
|
# The url needs to be recreated, patching url.regex is not an option Django 1.4's LocaleRegexProvider changed it.
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import uuid
|
import uuid
|
||||||
import re
|
import re
|
||||||
|
import django
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
@ -66,21 +67,45 @@ class ModelX(Base):
|
||||||
class ModelY(Base):
|
class ModelY(Base):
|
||||||
field_y = models.CharField(max_length=10)
|
field_y = models.CharField(max_length=10)
|
||||||
|
|
||||||
class Enhance_Plain(models.Model):
|
if django.VERSION[:2] > (1, 6):
|
||||||
field_p = models.CharField(max_length=10)
|
class Enhance_Plain(models.Model):
|
||||||
class Enhance_Base(ShowFieldTypeAndContent, PolymorphicModel):
|
field_p = models.CharField(max_length=10)
|
||||||
field_b = models.CharField(max_length=10)
|
class Enhance_Base(ShowFieldTypeAndContent, PolymorphicModel):
|
||||||
class Enhance_Inherit(Enhance_Base, Enhance_Plain):
|
base_id = models.AutoField(primary_key=True)
|
||||||
field_i = models.CharField(max_length=10)
|
field_b = models.CharField(max_length=10)
|
||||||
|
class Enhance_Inherit(Enhance_Base, Enhance_Plain):
|
||||||
|
field_i = models.CharField(max_length=10)
|
||||||
|
|
||||||
class DiamondBase(models.Model):
|
class DiamondBase(models.Model):
|
||||||
field_b = models.CharField(max_length=10)
|
field_b = models.CharField(max_length=10)
|
||||||
class DiamondX(DiamondBase):
|
class DiamondX(DiamondBase):
|
||||||
field_x = models.CharField(max_length=10)
|
x_id = models.AutoField(primary_key=True)
|
||||||
class DiamondY(DiamondBase):
|
field_x = models.CharField(max_length=10)
|
||||||
field_y = models.CharField(max_length=10)
|
class DiamondY(DiamondBase):
|
||||||
class DiamondXY(DiamondX, DiamondY):
|
y_id = models.AutoField(primary_key=True)
|
||||||
pass
|
field_y = models.CharField(max_length=10)
|
||||||
|
class DiamondXY(DiamondBase):
|
||||||
|
xy_id = models.AutoField(primary_key=True)
|
||||||
|
field_x = models.CharField(max_length=10)
|
||||||
|
field_y = models.CharField(max_length=10)
|
||||||
|
else:
|
||||||
|
class Enhance_Plain(models.Model):
|
||||||
|
field_p = models.CharField(max_length=10)
|
||||||
|
class Enhance_Base(ShowFieldTypeAndContent, PolymorphicModel):
|
||||||
|
field_b = models.CharField(max_length=10)
|
||||||
|
class Enhance_Inherit(Enhance_Base, Enhance_Plain):
|
||||||
|
field_i = models.CharField(max_length=10)
|
||||||
|
|
||||||
|
class DiamondBase(models.Model):
|
||||||
|
field_b = models.CharField(max_length=10)
|
||||||
|
class DiamondX(DiamondBase):
|
||||||
|
x_id = models.AutoField(primary_key=True)
|
||||||
|
field_x = models.CharField(max_length=10)
|
||||||
|
class DiamondY(DiamondBase):
|
||||||
|
y_id = models.AutoField(primary_key=True)
|
||||||
|
field_y = models.CharField(max_length=10)
|
||||||
|
class DiamondXY(DiamondX, DiamondY):
|
||||||
|
xy_id = models.AutoField(primary_key=True)
|
||||||
|
|
||||||
class RelationBase(ShowFieldTypeAndContent, PolymorphicModel):
|
class RelationBase(ShowFieldTypeAndContent, PolymorphicModel):
|
||||||
field_base = models.CharField(max_length=10)
|
field_base = models.CharField(max_length=10)
|
||||||
|
|
@ -110,6 +135,9 @@ class MyManagerQuerySet(PolymorphicQuerySet):
|
||||||
class MyManager(PolymorphicManager):
|
class MyManager(PolymorphicManager):
|
||||||
queryset_class = MyManagerQuerySet
|
queryset_class = MyManagerQuerySet
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return super(MyManager, self).get_queryset().order_by('-field1')
|
||||||
|
|
||||||
def get_query_set(self):
|
def get_query_set(self):
|
||||||
return super(MyManager, self).get_query_set().order_by('-field1')
|
return super(MyManager, self).get_query_set().order_by('-field1')
|
||||||
|
|
||||||
|
|
@ -143,9 +171,12 @@ class PlainMyManager(models.Manager):
|
||||||
def my_queryset_foo(self):
|
def my_queryset_foo(self):
|
||||||
return self.get_query_set().my_queryset_foo()
|
return self.get_query_set().my_queryset_foo()
|
||||||
|
|
||||||
def get_query_set(self):
|
def get_queryset(self):
|
||||||
return PlainMyManagerQuerySet(self.model, using=self._db)
|
return PlainMyManagerQuerySet(self.model, using=self._db)
|
||||||
|
|
||||||
|
def get_query_set(self):
|
||||||
|
return self.get_queryset()
|
||||||
|
|
||||||
class PlainParentModelWithManager(models.Model):
|
class PlainParentModelWithManager(models.Model):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -254,6 +285,10 @@ class PolymorphicTests(TestCase):
|
||||||
The test suite
|
The test suite
|
||||||
"""
|
"""
|
||||||
def test_diamond_inheritance(self):
|
def test_diamond_inheritance(self):
|
||||||
|
if django.VERSION[:2] > (1, 6):
|
||||||
|
print('')
|
||||||
|
print("# Django 1.7 doesn't allow multiple inheritance when two id fields exist. https://docs.djangoproject.com/en/dev/topics/db/models/#multiple-inheritance")
|
||||||
|
|
||||||
# Django diamond problem
|
# Django diamond problem
|
||||||
# https://code.djangoproject.com/ticket/10808
|
# https://code.djangoproject.com/ticket/10808
|
||||||
o1 = DiamondXY.objects.create(field_b='b', field_x='x', field_y='y')
|
o1 = DiamondXY.objects.create(field_b='b', field_x='x', field_y='y')
|
||||||
|
|
@ -616,11 +651,14 @@ class PolymorphicTests(TestCase):
|
||||||
Enhance_Inherit.objects.create(field_b='b-inherit', field_p='p', field_i='i')
|
Enhance_Inherit.objects.create(field_b='b-inherit', field_p='p', field_i='i')
|
||||||
|
|
||||||
qs = Enhance_Base.objects.all()
|
qs = Enhance_Base.objects.all()
|
||||||
self.assertEqual(repr(qs[0]), '<Enhance_Base: id 1, field_b (CharField) "b-base">')
|
if django.VERSION[:2] > (1, 6):
|
||||||
self.assertEqual(repr(qs[1]), '<Enhance_Inherit: id 2, field_b (CharField) "b-inherit", field_p (CharField) "p", field_i (CharField) "i">')
|
self.assertEqual(repr(qs[0]), '<Enhance_Base: base_id (AutoField/pk) 1, field_b (CharField) "b-base">')
|
||||||
|
self.assertEqual(repr(qs[1]), '<Enhance_Inherit: base_id (AutoField/pk) 2, field_b (CharField) "b-inherit", id 1, field_p (CharField) "p", field_i (CharField) "i">')
|
||||||
|
else:
|
||||||
|
self.assertEqual(repr(qs[0]), '<Enhance_Base: id 1, field_b (CharField) "b-base">')
|
||||||
|
self.assertEqual(repr(qs[1]), '<Enhance_Inherit: id 2, field_b (CharField) "b-inherit", field_p (CharField) "p", field_i (CharField) "i">')
|
||||||
self.assertEqual(len(qs), 2)
|
self.assertEqual(len(qs), 2)
|
||||||
|
|
||||||
|
|
||||||
def test_relation_base(self):
|
def test_relation_base(self):
|
||||||
# ForeignKey, ManyToManyField
|
# ForeignKey, ManyToManyField
|
||||||
obase = RelationBase.objects.create(field_base='base')
|
obase = RelationBase.objects.create(field_base='base')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue