Some more PEP 8 cleaning
parent
741abf4228
commit
bb06d6d12b
|
|
@ -6,6 +6,7 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from query import PolymorphicQuerySet
|
from query import PolymorphicQuerySet
|
||||||
|
|
||||||
|
|
||||||
class PolymorphicManager(models.Manager):
|
class PolymorphicManager(models.Manager):
|
||||||
"""
|
"""
|
||||||
Manager for PolymorphicModel
|
Manager for PolymorphicModel
|
||||||
|
|
|
||||||
|
|
@ -109,10 +109,10 @@ class PolymorphicModel(models.Model):
|
||||||
and all fields may be retrieved with this method.
|
and all fields may be retrieved with this method.
|
||||||
Each method call executes one db query (if necessary)."""
|
Each method call executes one db query (if necessary)."""
|
||||||
real_model = self.get_real_instance_class()
|
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)
|
return real_model.objects.get(pk=self.pk)
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, * args, ** kwargs):
|
def __init__(self, * args, ** kwargs):
|
||||||
"""Replace Django's inheritance accessor member functions for our model
|
"""Replace Django's inheritance accessor member functions for our model
|
||||||
(self.__class__) with our own versions.
|
(self.__class__) with our own versions.
|
||||||
|
|
@ -159,11 +159,13 @@ class PolymorphicModel(models.Model):
|
||||||
|
|
||||||
def add_model(model, as_ptr, result):
|
def add_model(model, as_ptr, result):
|
||||||
name = model.__name__.lower()
|
name = model.__name__.lower()
|
||||||
if as_ptr: name+='_ptr'
|
if as_ptr:
|
||||||
|
name += '_ptr'
|
||||||
result[name] = model
|
result[name] = model
|
||||||
|
|
||||||
def add_model_if_regular(model, as_ptr, result):
|
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 != self.__class__
|
||||||
and model != PolymorphicModel ):
|
and model != PolymorphicModel ):
|
||||||
add_model(model,as_ptr,result)
|
add_model(model,as_ptr,result)
|
||||||
|
|
@ -182,4 +184,3 @@ class PolymorphicModel(models.Model):
|
||||||
add_all_sub_models(self.__class__,result)
|
add_all_sub_models(self.__class__,result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -17,7 +17,6 @@ from django.db.models.query import CHUNK_SIZE # this is 100 for Dj
|
||||||
Polymorphic_QuerySet_objects_per_request = CHUNK_SIZE
|
Polymorphic_QuerySet_objects_per_request = CHUNK_SIZE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###################################################################################
|
###################################################################################
|
||||||
### PolymorphicQuerySet
|
### PolymorphicQuerySet
|
||||||
|
|
||||||
|
|
@ -97,7 +96,6 @@ class PolymorphicQuerySet(QuerySet):
|
||||||
# The "polymorphic" keyword argument is not supported anymore.
|
# The "polymorphic" keyword argument is not supported anymore.
|
||||||
#def extra(self, *args, **kwargs):
|
#def extra(self, *args, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
def _get_real_instances(self, base_result_objects):
|
def _get_real_instances(self, base_result_objects):
|
||||||
"""
|
"""
|
||||||
Polymorphic object loader
|
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=...)
|
# 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, (
|
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
|
base_result_objects_by_id[base_object.pk] = base_object
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue