diff options
| author | MichaĆ Modzelewski <michal.modzelewski@gmail.com> | 2015-01-02 02:39:31 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-01-12 18:15:34 -0500 |
| commit | 65246de7b1d70d25831ab394c4f4a75813f629fe (patch) | |
| tree | 618c5f030f9a77d240dc59b132dd1e152baca116 /django/db/models/sql/where.py | |
| parent | aa8ee6a5731b37b73635e7605521fb1a54a5c10d (diff) | |
Fixed #24031 -- Added CASE expressions to the ORM.
Diffstat (limited to 'django/db/models/sql/where.py')
| -rw-r--r-- | django/db/models/sql/where.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py index 10445555e0..cbb709dfc8 100644 --- a/django/db/models/sql/where.py +++ b/django/db/models/sql/where.py @@ -11,6 +11,7 @@ from django.conf import settings from django.db.models.fields import DateTimeField, Field from django.db.models.sql.datastructures import EmptyResultSet, Empty from django.utils.deprecation import RemovedInDjango19Warning +from django.utils.functional import cached_property from django.utils.six.moves import range from django.utils import timezone from django.utils import tree @@ -309,6 +310,30 @@ class WhereNode(tree.Node): clone.children.append(child) return clone + def relabeled_clone(self, change_map): + clone = self.clone() + clone.relabel_aliases(change_map) + return clone + + @cached_property + def contains_aggregate(self): + def _contains_aggregate(obj): + if not isinstance(obj, tree.Node): + return getattr(obj.lhs, 'contains_aggregate', False) or getattr(obj.rhs, 'contains_aggregate', False) + return any(_contains_aggregate(c) for c in obj.children) + + return _contains_aggregate(self) + + def refs_field(self, aggregate_types, field_types): + def _refs_field(obj, aggregate_types, field_types): + if not isinstance(obj, tree.Node): + if hasattr(obj.rhs, 'refs_field'): + return obj.rhs.refs_field(aggregate_types, field_types) + return False + return any(_refs_field(c, aggregate_types, field_types) for c in obj.children) + + return _refs_field(self, aggregate_types, field_types) + class EmptyWhere(WhereNode): def add(self, data, connector): |
