Merge branch 'django_1.7_support' of https://github.com/g3rd/django_polymorphic

Conflicts:
	docs/managers.rst
	polymorphic/admin.py
	polymorphic/manager.py
	polymorphic/tests.py
	runtests.py
fix_request_path_info
Diederik van der Boor 2014-09-22 15:42:35 +02:00
commit 981614e5c6
4 changed files with 62 additions and 18 deletions

View File

@ -31,6 +31,8 @@ Django as automatic manager for several purposes, including accessing
related objects. It must not filter objects and it's safest to use related objects. It must not filter objects and it's safest to use
the plain ``PolymorphicManager`` here. the plain ``PolymorphicManager`` here.
Note that get_query_set is deprecated in Django 1.8 and creates warnings in Django 1.7.
Manager Inheritance Manager Inheritance
------------------- -------------------
@ -65,6 +67,8 @@ regarding their start time and ``ArtProject.objects_ordered.most_recent()``
will return the ten most recent art projects. will return the ten most recent art projects.
. .
Note that get_query_set is deprecated in Django 1.8 and creates warnings in Django 1.7.
Using a Custom Queryset Class Using a Custom Queryset Class
----------------------------- -----------------------------

View File

@ -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
@ -281,7 +282,8 @@ 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 meta = self.model._meta
info = meta.app_label, getattr(meta, 'model_name', 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.

View File

@ -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):
class Enhance_Plain(models.Model):
field_p = models.CharField(max_length=10) field_p = models.CharField(max_length=10)
class Enhance_Base(ShowFieldTypeAndContent, PolymorphicModel): class Enhance_Base(ShowFieldTypeAndContent, PolymorphicModel):
base_id = models.AutoField(primary_key=True)
field_b = models.CharField(max_length=10) field_b = models.CharField(max_length=10)
class Enhance_Inherit(Enhance_Base, Enhance_Plain): class Enhance_Inherit(Enhance_Base, Enhance_Plain):
field_i = models.CharField(max_length=10) 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):
x_id = models.AutoField(primary_key=True)
field_x = models.CharField(max_length=10) field_x = models.CharField(max_length=10)
class DiamondY(DiamondBase): class DiamondY(DiamondBase):
y_id = models.AutoField(primary_key=True)
field_y = models.CharField(max_length=10) field_y = models.CharField(max_length=10)
class DiamondXY(DiamondX, DiamondY): class DiamondXY(DiamondBase):
pass 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)
@ -260,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')
@ -622,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()
if django.VERSION[:2] > (1, 6):
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[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(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')

View File

@ -11,6 +11,7 @@ envlist=
py32-django15, py32-django15,
py32-django16, py32-django16,
py32-django17,
py33-django15, py33-django15,
py33-django16, py33-django16,
@ -70,6 +71,11 @@ basepython=python3.2
deps= deps=
django==1.6 django==1.6
[testenv:py32-django17]
basepython=python3.2
deps=
django==1.7
[testenv:py33-django15] [testenv:py33-django15]
basepython=python3.3 basepython=python3.3
deps= deps=