Last active
August 29, 2015 14:27
-
-
Save jarshwah/c646b4db9d1138dcc0ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/tests/foreign_object/models.py b/tests/foreign_object/models.py | |
index e774421..1c163f5 100644 | |
--- a/tests/foreign_object/models.py | |
+++ b/tests/foreign_object/models.py | |
@@ -278,7 +278,7 @@ class BrokenContainsRelation(StartsWithRelation): | |
@python_2_unicode_compatible | |
class SlugPage(models.Model): | |
- slug = models.TextField() | |
+ slug = models.CharField(max_length=20) | |
descendants = StartsWithRelation( | |
'self', | |
from_fields=['slug'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/tests/foreign_object/models.py b/tests/foreign_object/models.py | |
index e774421..ba66e4b 100644 | |
--- a/tests/foreign_object/models.py | |
+++ b/tests/foreign_object/models.py | |
@@ -218,6 +218,18 @@ class CustomForeignObjectRel(ForeignObjectRel): | |
return self.name | |
+class CustomStartsWith(StartsWith): | |
+ def process_rhs(self, compiler, connection, rhs=None): | |
+ rhs = rhs or self.rhs | |
+ rhs_sql, params = compiler.compile(rhs) | |
+ field_internal_type = self.rhs.output_field.get_internal_type() | |
+ db_type = self.rhs.output_field.db_type(connection=connection) | |
+ rhs_sql = connection.ops.field_cast_sql( | |
+ db_type, field_internal_type) % rhs_sql | |
+ rhs_sql = connection.ops.lookup_cast(self.lookup_name, field_internal_type) % rhs_sql | |
+ return rhs_sql, params | |
+ | |
+ | |
class StartsWithRelation(models.ForeignObject): | |
""" | |
A ForeignObject that uses starts-with operator in its joins, instead of | |
@@ -247,7 +259,7 @@ class StartsWithRelation(models.ForeignObject): | |
def get_extra_restriction(self, where_class, alias, related_alias): | |
to_field = self.remote_field.model._meta.get_field(self.to_fields[0]) | |
from_field = self.model._meta.get_field(self.from_fields[0]) | |
- return StartsWith(to_field.get_col(alias), from_field.get_col(related_alias)) | |
+ return CustomStartsWith(to_field.get_col(alias), from_field.get_col(related_alias)) | |
def get_joining_columns(self, reverse_join=False): | |
return tuple() | |
@@ -292,7 +304,7 @@ class SlugPage(models.Model): | |
) | |
class Meta: | |
- ordering = ['slug'] | |
+ ordering = ['id'] | |
def __str__(self): | |
return "SlugPage %s" % self.slug | |
diff --git a/tests/foreign_object/tests.py b/tests/foreign_object/tests.py | |
index 748d292..a94cc2d 100644 | |
--- a/tests/foreign_object/tests.py | |
+++ b/tests/foreign_object/tests.py | |
@@ -437,7 +437,7 @@ class RestrictedConditionsTests(TestCase): | |
""" | |
a = SlugPage.objects.get(slug='a') | |
self.assertListEqual( | |
- [p.slug for p in SlugPage.objects.filter(ascendants=a)], | |
+ [p.slug for p in SlugPage.objects.filter(ascendants=a).order_by('id')], | |
['a', 'a/a', 'a/b', 'a/b/a'], | |
) | |
self.assertEqual( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment