translate_polymorphic_Q_object: fixed test case, and made the function a member of PolymorphicObject.
Minor test fixes: warnings fixed, test_tool.py renamed as it's no test
This commit is contained in:
@@ -27,6 +27,7 @@ from base import PolymorphicModelBase
|
||||
from manager import PolymorphicManager
|
||||
from query import PolymorphicQuerySet
|
||||
from showfields import ShowFieldType
|
||||
from query_translate import translate_polymorphic_Q_object
|
||||
|
||||
|
||||
###################################################################################
|
||||
@@ -76,6 +77,10 @@ class PolymorphicModel(models.Model):
|
||||
objects = PolymorphicManager()
|
||||
base_objects = models.Manager()
|
||||
|
||||
@classmethod
|
||||
def translate_polymorphic_Q_object(self_class,q):
|
||||
return translate_polymorphic_Q_object(self_class,q)
|
||||
|
||||
def pre_save_polymorphic(self):
|
||||
"""Normally not needed.
|
||||
This function may be called manually in special use-cases. When the object
|
||||
|
||||
@@ -141,7 +141,7 @@ class BlogEntry(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
text = models.CharField(max_length=10)
|
||||
|
||||
class BlogEntry_limit_choices_to(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
blog = models.ForeignKey(BlogBase, limit_choices_to=translate_polymorphic_Q_object(BlogBase, Q(instance_of=BlogA) ) )
|
||||
blog = models.ForeignKey(BlogBase)
|
||||
text = models.CharField(max_length=10)
|
||||
|
||||
class ModelFieldNameTest(ShowFieldType, PolymorphicModel):
|
||||
@@ -159,7 +159,7 @@ class InitTestModelSubclass(InitTestModel):
|
||||
|
||||
# UUID tests won't work with Django 1.1
|
||||
if not (django_VERSION[0] <= 1 and django_VERSION[1] <= 1):
|
||||
try: from polymorphic.test_tools import UUIDField
|
||||
try: from polymorphic.tools_for_tests import UUIDField
|
||||
except: pass
|
||||
if 'UUIDField' in globals():
|
||||
import uuid
|
||||
@@ -369,6 +369,12 @@ __test__ = {"doctest": """
|
||||
<Model2C: id 3, field1 (CharField), field2 (CharField), field3 (CharField)>,
|
||||
<Model2D: id 4, field1 (CharField), field2 (CharField), field3 (CharField), field4 (CharField)> ]
|
||||
|
||||
# translate_polymorphic_Q_object
|
||||
>>> q=Model2A.translate_polymorphic_Q_object( Q(instance_of=Model2C) )
|
||||
>>> Model2A.objects.filter(q)
|
||||
[ <Model2C: id 3, field1 (CharField), field2 (CharField), field3 (CharField)>,
|
||||
<Model2D: id 4, field1 (CharField), field2 (CharField), field3 (CharField), field4 (CharField)> ]
|
||||
|
||||
|
||||
### test inheritance pointers & _base_managers
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ class UUIDField(models.CharField):
|
||||
else:
|
||||
raise UUIDVersionError("UUID version %s is not valid." % self.version)
|
||||
|
||||
def db_type(self):
|
||||
def db_type(self, connection):
|
||||
from django.conf import settings
|
||||
return UUIDField._CREATE_COLUMN_TYPES.get(settings.DATABASE_ENGINE, "char(%s)" % self.max_length)
|
||||
|
||||
@@ -122,7 +122,7 @@ class UUIDField(models.CharField):
|
||||
setattr(model_instance, self.attname, value)
|
||||
return value
|
||||
|
||||
def get_db_prep_value(self, value):
|
||||
def get_db_prep_value(self, value, connection, prepared):
|
||||
"""Casts uuid.UUID values into the format expected by the back end for use in queries"""
|
||||
if isinstance(value, uuid.UUID):
|
||||
return smart_unicode(value)
|
||||
Reference in New Issue
Block a user