Fix a handful of warnings and remove some unused compatibility code
parent
977c73c4c3
commit
24e6b21204
|
|
@ -42,36 +42,34 @@ class ModelAAdmin(PolymorphicParentModelAdmin):
|
||||||
admin.site.register(ModelA, ModelAAdmin)
|
admin.site.register(ModelA, ModelAAdmin)
|
||||||
|
|
||||||
|
|
||||||
if 'Model2A' in globals():
|
class Model2AChildAdmin(PolymorphicChildModelAdmin):
|
||||||
class Model2AChildAdmin(PolymorphicChildModelAdmin):
|
base_model = Model2A
|
||||||
base_model = Model2A
|
|
||||||
|
|
||||||
class Model2AAdmin(PolymorphicParentModelAdmin):
|
class Model2AAdmin(PolymorphicParentModelAdmin):
|
||||||
base_model = Model2A
|
base_model = Model2A
|
||||||
list_filter = (PolymorphicChildModelFilter,)
|
list_filter = (PolymorphicChildModelFilter,)
|
||||||
child_models = (
|
child_models = (
|
||||||
(Model2A, Model2AChildAdmin),
|
(Model2A, Model2AChildAdmin),
|
||||||
(Model2B, Model2AChildAdmin),
|
(Model2B, Model2AChildAdmin),
|
||||||
(Model2C, Model2AChildAdmin),
|
(Model2C, Model2AChildAdmin),
|
||||||
)
|
)
|
||||||
|
|
||||||
admin.site.register(Model2A, Model2AAdmin)
|
admin.site.register(Model2A, Model2AAdmin)
|
||||||
|
|
||||||
|
|
||||||
if 'UUIDModelA' in globals():
|
class UUIDModelAChildAdmin(PolymorphicChildModelAdmin):
|
||||||
class UUIDModelAChildAdmin(PolymorphicChildModelAdmin):
|
base_model = UUIDModelA
|
||||||
base_model = UUIDModelA
|
|
||||||
|
|
||||||
class UUIDModelAAdmin(PolymorphicParentModelAdmin):
|
class UUIDModelAAdmin(PolymorphicParentModelAdmin):
|
||||||
base_model = UUIDModelA
|
base_model = UUIDModelA
|
||||||
list_filter = (PolymorphicChildModelFilter,)
|
list_filter = (PolymorphicChildModelFilter,)
|
||||||
child_models = (
|
child_models = (
|
||||||
(UUIDModelA, UUIDModelAChildAdmin),
|
(UUIDModelA, UUIDModelAChildAdmin),
|
||||||
(UUIDModelB, UUIDModelAChildAdmin),
|
(UUIDModelB, UUIDModelAChildAdmin),
|
||||||
(UUIDModelC, UUIDModelAChildAdmin),
|
(UUIDModelC, UUIDModelAChildAdmin),
|
||||||
)
|
)
|
||||||
|
|
||||||
admin.site.register(UUIDModelA, UUIDModelAAdmin)
|
admin.site.register(UUIDModelA, UUIDModelAAdmin)
|
||||||
|
|
||||||
|
|
||||||
class ProxyChildAdmin(PolymorphicChildModelAdmin):
|
class ProxyChildAdmin(PolymorphicChildModelAdmin):
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import django
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from polymorphic.models import PolymorphicModel
|
from polymorphic.models import PolymorphicModel
|
||||||
|
|
@ -26,27 +27,25 @@ class nModelB(nModelA):
|
||||||
class nModelC(nModelB):
|
class nModelC(nModelB):
|
||||||
field3 = models.CharField(max_length=10)
|
field3 = models.CharField(max_length=10)
|
||||||
|
|
||||||
# for Django 1.2+, test models with same names in different apps
|
class Model2A(PolymorphicModel):
|
||||||
# (the other models with identical names are in polymorphic/tests.py)
|
field1 = models.CharField(max_length=10)
|
||||||
from django import VERSION as django_VERSION
|
class Model2B(Model2A):
|
||||||
if not (django_VERSION[0]<=1 and django_VERSION[1]<=1):
|
field2 = models.CharField(max_length=10)
|
||||||
class Model2A(PolymorphicModel):
|
class Model2C(Model2B):
|
||||||
field1 = models.CharField(max_length=10)
|
field3 = models.CharField(max_length=10)
|
||||||
class Model2B(Model2A):
|
|
||||||
field2 = models.CharField(max_length=10)
|
|
||||||
class Model2C(Model2B):
|
|
||||||
field3 = models.CharField(max_length=10)
|
|
||||||
|
|
||||||
try: from polymorphic.test_tools import UUIDField
|
if django.VERSION < (1,8):
|
||||||
except: pass
|
from polymorphic.tools_for_tests import UUIDField
|
||||||
if 'UUIDField' in globals():
|
else:
|
||||||
class UUIDModelA(ShowFieldTypeAndContent, PolymorphicModel):
|
from django.db.models import UUIDField
|
||||||
uuid_primary_key = UUIDField(primary_key = True)
|
|
||||||
field1 = models.CharField(max_length=10)
|
class UUIDModelA(ShowFieldTypeAndContent, PolymorphicModel):
|
||||||
class UUIDModelB(UUIDModelA):
|
uuid_primary_key = UUIDField(primary_key = True)
|
||||||
field2 = models.CharField(max_length=10)
|
field1 = models.CharField(max_length=10)
|
||||||
class UUIDModelC(UUIDModelB):
|
class UUIDModelB(UUIDModelA):
|
||||||
field3 = models.CharField(max_length=10)
|
field2 = models.CharField(max_length=10)
|
||||||
|
class UUIDModelC(UUIDModelB):
|
||||||
|
field3 = models.CharField(max_length=10)
|
||||||
|
|
||||||
class ProxyBase(PolymorphicModel):
|
class ProxyBase(PolymorphicModel):
|
||||||
title = models.CharField(max_length=200)
|
title = models.CharField(max_length=200)
|
||||||
|
|
|
||||||
|
|
@ -239,8 +239,8 @@ class PolymorphicQuerySet(QuerySet):
|
||||||
if real_class != real_concrete_class:
|
if real_class != real_concrete_class:
|
||||||
real_object = transmogrify(real_class, real_object)
|
real_object = transmogrify(real_class, real_object)
|
||||||
|
|
||||||
if self.query.aggregates:
|
if self.query.annotations:
|
||||||
for anno_field_name in six.iterkeys(self.query.aggregates):
|
for anno_field_name in six.iterkeys(self.query.annotations):
|
||||||
attr = getattr(base_result_objects_by_id[o_pk], anno_field_name)
|
attr = getattr(base_result_objects_by_id[o_pk], anno_field_name)
|
||||||
setattr(real_object, anno_field_name, attr)
|
setattr(real_object, anno_field_name, attr)
|
||||||
|
|
||||||
|
|
@ -255,8 +255,8 @@ class PolymorphicQuerySet(QuerySet):
|
||||||
resultlist = [results[ordered_id] for ordered_id in ordered_id_list if ordered_id in results]
|
resultlist = [results[ordered_id] for ordered_id in ordered_id_list if ordered_id in results]
|
||||||
|
|
||||||
# set polymorphic_annotate_names in all objects (currently just used for debugging/printing)
|
# set polymorphic_annotate_names in all objects (currently just used for debugging/printing)
|
||||||
if self.query.aggregates:
|
if self.query.annotations:
|
||||||
annotate_names = list(six.iterkeys(self.query.aggregates)) # get annotate field list
|
annotate_names = list(six.iterkeys(self.query.annotations)) # get annotate field list
|
||||||
for real_object in resultlist:
|
for real_object in resultlist:
|
||||||
real_object.polymorphic_annotate_names = annotate_names
|
real_object.polymorphic_annotate_names = annotate_names
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ def translate_polymorphic_field_path(queryset_model, field_path):
|
||||||
# so no tripple ClassName___field was intended.
|
# so no tripple ClassName___field was intended.
|
||||||
try:
|
try:
|
||||||
# rel = (field_object, model, direct, m2m)
|
# rel = (field_object, model, direct, m2m)
|
||||||
field = queryset_model._meta.get_field_by_name(classname)[0]
|
field = queryset_model._meta.get_field(classname)
|
||||||
if isinstance(field, RelatedObject):
|
if isinstance(field, RelatedObject):
|
||||||
# Can also test whether the field exists in the related object to avoid ambiguity between
|
# Can also test whether the field exists in the related object to avoid ambiguity between
|
||||||
# class names and field names, but that never happens when your class names are in CamelCase.
|
# class names and field names, but that never happens when your class names are in CamelCase.
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import re
|
||||||
import django
|
import django
|
||||||
try:
|
try:
|
||||||
from unittest import skipIf
|
from unittest import skipIf
|
||||||
except:
|
except ImportError:
|
||||||
# python<2.7
|
# python<2.7
|
||||||
from django.utils.unittest import skipIf
|
from django.utils.unittest import skipIf
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
|
|
@ -23,7 +23,11 @@ from polymorphic.models import PolymorphicModel
|
||||||
from polymorphic.manager import PolymorphicManager
|
from polymorphic.manager import PolymorphicManager
|
||||||
from polymorphic.query import PolymorphicQuerySet
|
from polymorphic.query import PolymorphicQuerySet
|
||||||
from polymorphic import ShowFieldContent, ShowFieldType, ShowFieldTypeAndContent
|
from polymorphic import ShowFieldContent, ShowFieldType, ShowFieldTypeAndContent
|
||||||
from polymorphic.tools_for_tests import UUIDField
|
try:
|
||||||
|
from django.db.models import UUIDField
|
||||||
|
except ImportError:
|
||||||
|
# django<1.8
|
||||||
|
from polymorphic.tools_for_tests import UUIDField
|
||||||
|
|
||||||
|
|
||||||
class PlainA(models.Model):
|
class PlainA(models.Model):
|
||||||
|
|
@ -212,15 +216,15 @@ class Bottom(Middle):
|
||||||
author = models.CharField(max_length=50)
|
author = models.CharField(max_length=50)
|
||||||
|
|
||||||
class UUIDProject(ShowFieldTypeAndContent, PolymorphicModel):
|
class UUIDProject(ShowFieldTypeAndContent, PolymorphicModel):
|
||||||
uuid_primary_key = UUIDField(primary_key = True)
|
uuid_primary_key = UUIDField(primary_key = True, default=uuid.uuid1)
|
||||||
topic = models.CharField(max_length = 30)
|
topic = models.CharField(max_length = 30)
|
||||||
class UUIDArtProject(UUIDProject):
|
class UUIDArtProject(UUIDProject):
|
||||||
artist = models.CharField(max_length = 30)
|
artist = models.CharField(max_length = 30)
|
||||||
class UUIDResearchProject(UUIDProject):
|
class UUIDResearchProject(UUIDProject):
|
||||||
supervisor = models.CharField(max_length = 30)
|
supervisor = models.CharField(max_length = 30)
|
||||||
|
|
||||||
class UUIDPlainA(models.Model):
|
class UUIDPlainA(models.Model):
|
||||||
uuid_primary_key = UUIDField(primary_key = True)
|
uuid_primary_key = UUIDField(primary_key = True, default=uuid.uuid1)
|
||||||
field1 = models.CharField(max_length=10)
|
field1 = models.CharField(max_length=10)
|
||||||
class UUIDPlainB(UUIDPlainA):
|
class UUIDPlainB(UUIDPlainA):
|
||||||
field2 = models.CharField(max_length=10)
|
field2 = models.CharField(max_length=10)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
# Compatibility module for Django < 1.8
|
||||||
|
|
||||||
####################################################################
|
|
||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
@ -9,6 +6,7 @@ from django.db import models
|
||||||
from django.utils.encoding import smart_text
|
from django.utils.encoding import smart_text
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
||||||
|
|
||||||
class UUIDVersionError(Exception):
|
class UUIDVersionError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue