From fb9ac5729d309f6ec59e4089b7ab04378cb9082a Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Thu, 7 May 2009 16:12:08 +0000 Subject: [PATCH] Fixed #10153: foreign key `gte` and `lte` lookups now work. Thanks, joelhooks and adurdin. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10692 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/fields/related.py | 2 +- tests/regressiontests/model_regress/tests.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/regressiontests/model_regress/tests.py diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 679b37cfca..419695b74b 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -155,7 +155,7 @@ class RelatedField(object): # get_(next/prev)_by_date work; other lookups are not allowed since that # gets messy pretty quick. This is a good candidate for some refactoring # in the future. - if lookup_type in ['exact', 'gt', 'lt']: + if lookup_type in ['exact', 'gt', 'lt', 'gte', 'lte']: return [pk_trace(value)] if lookup_type in ('range', 'in'): return [pk_trace(v) for v in value] diff --git a/tests/regressiontests/model_regress/tests.py b/tests/regressiontests/model_regress/tests.py new file mode 100644 index 0000000000..0257c63d8c --- /dev/null +++ b/tests/regressiontests/model_regress/tests.py @@ -0,0 +1,16 @@ +from models import Worker +from django.test import TestCase + +class RelatedModelOrderedLookupTest(TestCase): + """ + Regression test for #10153: foreign key __gte and __lte lookups. + """ + + # The bug is that the following queries would raise: + # "TypeError: Related Field has invalid lookup: gte" + + def test_related_gte_lookup(self): + Worker.objects.filter(department__gte=0) + + def test_related_lte_lookup(self): + Worker.objects.filter(department__lte=0)