Some more PEP 8 cleaning

fix_request_path_info
German M. Bravo 2011-11-25 23:37:55 -06:00 committed by Christopher Glass
parent 741abf4228
commit bb06d6d12b
3 changed files with 9 additions and 8 deletions

View File

@ -6,6 +6,7 @@
from django.db import models
from query import PolymorphicQuerySet
class PolymorphicManager(models.Manager):
"""
Manager for PolymorphicModel

View File

@ -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

View File

@ -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