From bb06d6d12bf2a0168618954651c27ed13611d4e4 Mon Sep 17 00:00:00 2001 From: "German M. Bravo" Date: Fri, 25 Nov 2011 23:37:55 -0600 Subject: [PATCH] Some more PEP 8 cleaning --- polymorphic/manager.py | 1 + polymorphic/polymorphic_model.py | 11 ++++++----- polymorphic/query.py | 5 ++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/polymorphic/manager.py b/polymorphic/manager.py index 802daf1..10e626e 100644 --- a/polymorphic/manager.py +++ b/polymorphic/manager.py @@ -6,6 +6,7 @@ from django.db import models from query import PolymorphicQuerySet + class PolymorphicManager(models.Manager): """ Manager for PolymorphicModel diff --git a/polymorphic/polymorphic_model.py b/polymorphic/polymorphic_model.py index eb68694..f69e2d2 100644 --- a/polymorphic/polymorphic_model.py +++ b/polymorphic/polymorphic_model.py @@ -109,10 +109,10 @@ class PolymorphicModel(models.Model): and all fields may be retrieved with this method. Each method call executes one db query (if necessary).""" real_model = self.get_real_instance_class() - if real_model == self.__class__: return self + if real_model == self.__class__: + return self return real_model.objects.get(pk=self.pk) - def __init__(self, * args, ** kwargs): """Replace Django's inheritance accessor member functions for our model (self.__class__) with our own versions. @@ -159,11 +159,13 @@ class PolymorphicModel(models.Model): def add_model(model, as_ptr, result): name = model.__name__.lower() - if as_ptr: name+='_ptr' + if as_ptr: + name += '_ptr' result[name] = model def add_model_if_regular(model, as_ptr, result): - if ( issubclass(model, models.Model) and model != models.Model + if (issubclass(model, models.Model) + and model != models.Model and model != self.__class__ and model != PolymorphicModel ): add_model(model,as_ptr,result) @@ -182,4 +184,3 @@ class PolymorphicModel(models.Model): add_all_sub_models(self.__class__,result) return result - \ No newline at end of file diff --git a/polymorphic/query.py b/polymorphic/query.py index 31a124e..e544ab5 100644 --- a/polymorphic/query.py +++ b/polymorphic/query.py @@ -17,7 +17,6 @@ from django.db.models.query import CHUNK_SIZE # this is 100 for Dj Polymorphic_QuerySet_objects_per_request = CHUNK_SIZE - ################################################################################### ### PolymorphicQuerySet @@ -97,7 +96,6 @@ class PolymorphicQuerySet(QuerySet): # The "polymorphic" keyword argument is not supported anymore. #def extra(self, *args, **kwargs): - def _get_real_instances(self, base_result_objects): """ Polymorphic object loader @@ -143,7 +141,8 @@ class PolymorphicQuerySet(QuerySet): # check if id of the result object occeres more than once - this can happen e.g. with base_objects.extra(tables=...) assert not base_object.pk in base_result_objects_by_id, ( - "django_polymorphic: result objects do not have unique primary keys - model "+unicode(self.model) ) + "django_polymorphic: result objects do not have unique primary keys - model " + unicode(self.model) + ) base_result_objects_by_id[base_object.pk] = base_object