Fix a handful of warnings and remove some unused compatibility code
parent
977c73c4c3
commit
24e6b21204
|
|
@ -42,11 +42,10 @@ class ModelAAdmin(PolymorphicParentModelAdmin):
|
|||
admin.site.register(ModelA, ModelAAdmin)
|
||||
|
||||
|
||||
if 'Model2A' in globals():
|
||||
class Model2AChildAdmin(PolymorphicChildModelAdmin):
|
||||
class Model2AChildAdmin(PolymorphicChildModelAdmin):
|
||||
base_model = Model2A
|
||||
|
||||
class Model2AAdmin(PolymorphicParentModelAdmin):
|
||||
class Model2AAdmin(PolymorphicParentModelAdmin):
|
||||
base_model = Model2A
|
||||
list_filter = (PolymorphicChildModelFilter,)
|
||||
child_models = (
|
||||
|
|
@ -55,14 +54,13 @@ if 'Model2A' in globals():
|
|||
(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
|
||||
|
||||
class UUIDModelAAdmin(PolymorphicParentModelAdmin):
|
||||
class UUIDModelAAdmin(PolymorphicParentModelAdmin):
|
||||
base_model = UUIDModelA
|
||||
list_filter = (PolymorphicChildModelFilter,)
|
||||
child_models = (
|
||||
|
|
@ -71,7 +69,7 @@ if 'UUIDModelA' in globals():
|
|||
(UUIDModelC, UUIDModelAChildAdmin),
|
||||
)
|
||||
|
||||
admin.site.register(UUIDModelA, UUIDModelAAdmin)
|
||||
admin.site.register(UUIDModelA, UUIDModelAAdmin)
|
||||
|
||||
|
||||
class ProxyChildAdmin(PolymorphicChildModelAdmin):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import django
|
||||
from django.db import models
|
||||
|
||||
from polymorphic.models import PolymorphicModel
|
||||
|
|
@ -26,26 +27,24 @@ class nModelB(nModelA):
|
|||
class nModelC(nModelB):
|
||||
field3 = models.CharField(max_length=10)
|
||||
|
||||
# for Django 1.2+, test models with same names in different apps
|
||||
# (the other models with identical names are in polymorphic/tests.py)
|
||||
from django import VERSION as django_VERSION
|
||||
if not (django_VERSION[0]<=1 and django_VERSION[1]<=1):
|
||||
class Model2A(PolymorphicModel):
|
||||
class Model2A(PolymorphicModel):
|
||||
field1 = models.CharField(max_length=10)
|
||||
class Model2B(Model2A):
|
||||
class Model2B(Model2A):
|
||||
field2 = models.CharField(max_length=10)
|
||||
class Model2C(Model2B):
|
||||
class Model2C(Model2B):
|
||||
field3 = models.CharField(max_length=10)
|
||||
|
||||
try: from polymorphic.test_tools import UUIDField
|
||||
except: pass
|
||||
if 'UUIDField' in globals():
|
||||
class UUIDModelA(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
if django.VERSION < (1,8):
|
||||
from polymorphic.tools_for_tests import UUIDField
|
||||
else:
|
||||
from django.db.models import UUIDField
|
||||
|
||||
class UUIDModelA(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
uuid_primary_key = UUIDField(primary_key = True)
|
||||
field1 = models.CharField(max_length=10)
|
||||
class UUIDModelB(UUIDModelA):
|
||||
class UUIDModelB(UUIDModelA):
|
||||
field2 = models.CharField(max_length=10)
|
||||
class UUIDModelC(UUIDModelB):
|
||||
class UUIDModelC(UUIDModelB):
|
||||
field3 = models.CharField(max_length=10)
|
||||
|
||||
class ProxyBase(PolymorphicModel):
|
||||
|
|
|
|||
|
|
@ -239,8 +239,8 @@ class PolymorphicQuerySet(QuerySet):
|
|||
if real_class != real_concrete_class:
|
||||
real_object = transmogrify(real_class, real_object)
|
||||
|
||||
if self.query.aggregates:
|
||||
for anno_field_name in six.iterkeys(self.query.aggregates):
|
||||
if self.query.annotations:
|
||||
for anno_field_name in six.iterkeys(self.query.annotations):
|
||||
attr = getattr(base_result_objects_by_id[o_pk], anno_field_name)
|
||||
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]
|
||||
|
||||
# set polymorphic_annotate_names in all objects (currently just used for debugging/printing)
|
||||
if self.query.aggregates:
|
||||
annotate_names = list(six.iterkeys(self.query.aggregates)) # get annotate field list
|
||||
if self.query.annotations:
|
||||
annotate_names = list(six.iterkeys(self.query.annotations)) # get annotate field list
|
||||
for real_object in resultlist:
|
||||
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.
|
||||
try:
|
||||
# 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):
|
||||
# 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.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import re
|
|||
import django
|
||||
try:
|
||||
from unittest import skipIf
|
||||
except:
|
||||
except ImportError:
|
||||
# python<2.7
|
||||
from django.utils.unittest import skipIf
|
||||
from django.db.models.query import QuerySet
|
||||
|
|
@ -23,7 +23,11 @@ from polymorphic.models import PolymorphicModel
|
|||
from polymorphic.manager import PolymorphicManager
|
||||
from polymorphic.query import PolymorphicQuerySet
|
||||
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):
|
||||
|
|
@ -212,7 +216,7 @@ class Bottom(Middle):
|
|||
author = models.CharField(max_length=50)
|
||||
|
||||
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)
|
||||
class UUIDArtProject(UUIDProject):
|
||||
artist = models.CharField(max_length = 30)
|
||||
|
|
@ -220,7 +224,7 @@ class UUIDResearchProject(UUIDProject):
|
|||
supervisor = models.CharField(max_length = 30)
|
||||
|
||||
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)
|
||||
class UUIDPlainB(UUIDPlainA):
|
||||
field2 = models.CharField(max_length=10)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
####################################################################
|
||||
|
||||
# Compatibility module for Django < 1.8
|
||||
import uuid
|
||||
|
||||
from django import forms
|
||||
|
|
@ -9,6 +6,7 @@ from django.db import models
|
|||
from django.utils.encoding import smart_text
|
||||
from django.utils import six
|
||||
|
||||
|
||||
class UUIDVersionError(Exception):
|
||||
pass
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue