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.pyfix_request_path_info
commit
981614e5c6
|
|
@ -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
|
||||
the plain ``PolymorphicManager`` here.
|
||||
|
||||
Note that get_query_set is deprecated in Django 1.8 and creates warnings in Django 1.7.
|
||||
|
||||
Manager Inheritance
|
||||
-------------------
|
||||
|
||||
|
|
@ -65,6 +67,8 @@ regarding their start time and ``ArtProject.objects_ordered.most_recent()``
|
|||
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
|
||||
-----------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ from django.utils.http import urlencode
|
|||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
try:
|
||||
# Django 1.6 implements this
|
||||
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.
|
||||
"""
|
||||
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.
|
||||
# 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
|
||||
import uuid
|
||||
import re
|
||||
import django
|
||||
from django.db.models.query import QuerySet
|
||||
|
||||
from django.test import TestCase
|
||||
|
|
@ -66,21 +67,45 @@ class ModelX(Base):
|
|||
class ModelY(Base):
|
||||
field_y = models.CharField(max_length=10)
|
||||
|
||||
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)
|
||||
if django.VERSION[:2] > (1, 6):
|
||||
class Enhance_Plain(models.Model):
|
||||
field_p = models.CharField(max_length=10)
|
||||
class Enhance_Base(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
base_id = models.AutoField(primary_key=True)
|
||||
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):
|
||||
field_x = models.CharField(max_length=10)
|
||||
class DiamondY(DiamondBase):
|
||||
field_y = models.CharField(max_length=10)
|
||||
class DiamondXY(DiamondX, DiamondY):
|
||||
pass
|
||||
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(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):
|
||||
field_base = models.CharField(max_length=10)
|
||||
|
|
@ -260,6 +285,10 @@ class PolymorphicTests(TestCase):
|
|||
The test suite
|
||||
"""
|
||||
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
|
||||
# https://code.djangoproject.com/ticket/10808
|
||||
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')
|
||||
|
||||
qs = Enhance_Base.objects.all()
|
||||
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">')
|
||||
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[1]), '<Enhance_Inherit: id 2, field_b (CharField) "b-inherit", field_p (CharField) "p", field_i (CharField) "i">')
|
||||
self.assertEqual(len(qs), 2)
|
||||
|
||||
|
||||
def test_relation_base(self):
|
||||
# ForeignKey, ManyToManyField
|
||||
obase = RelationBase.objects.create(field_base='base')
|
||||
|
|
|
|||
Loading…
Reference in New Issue