diff -r ad6737af409f django/db/models/sql/query.py
a
|
b
|
|
14 | 14 | from django.db import connections, DEFAULT_DB_ALIAS |
15 | 15 | from django.db.models import signals |
16 | 16 | from django.db.models.fields import FieldDoesNotExist |
| 17 | from django.db.models.expressions import ExpressionNode |
17 | 18 | from django.db.models.query_utils import select_related_descend, InvalidQuery |
18 | 19 | from django.db.models.sql import aggregates as base_aggregates_module |
19 | 20 | from django.db.models.sql.constants import * |
… |
… |
|
1002 | 1003 | value = True |
1003 | 1004 | elif callable(value): |
1004 | 1005 | value = value() |
1005 | | elif hasattr(value, 'evaluate'): |
| 1006 | elif hasattr(value, 'prepare') and hasattr(value, 'evaluate')\ |
| 1007 | and callable(value.prepare) and callable(value.evaluate): |
1006 | 1008 | # If value is a query expression, evaluate it |
1007 | 1009 | value = SQLEvaluator(value, self) |
1008 | 1010 | having_clause = value.contains_aggregate |
diff -r ad6737af409f tests/regressiontests/model_regress/tests.py
a
|
b
|
|
1 | | from models import Worker |
| 1 | from models import Worker, Department |
2 | 2 | from django.test import TestCase |
3 | 3 | |
4 | 4 | class RelatedModelOrderedLookupTest(TestCase): |
… |
… |
|
14 | 14 | |
15 | 15 | def test_related_lte_lookup(self): |
16 | 16 | Worker.objects.filter(department__lte=0) |
| 17 | |
| 18 | |
| 19 | class EvaluateMethodTest(TestCase): |
| 20 | """ |
| 21 | Regression test for #13640: cannot filter by objects with 'evaluate' attr |
| 22 | """ |
| 23 | |
| 24 | def test_model_with_evaluate_method(self): |
| 25 | """ |
| 26 | Ensures that you can filter by objects that have an 'evaluate' attr |
| 27 | """ |
| 28 | dept = Department.objects.create(pk=1, name='abc') |
| 29 | dept.evaluate = 'abc' |
| 30 | Worker.objects.filter(department=dept) |