From 25f76833a3655395e5cd2224ee82707c7e96632e Mon Sep 17 00:00:00 2001 From: lyssom <569810240@qq.com> Date: Wed, 26 May 2021 14:40:03 +0800 Subject: [PATCH] use Q function support having --- src/infi/clickhouse_orm/query.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/infi/clickhouse_orm/query.py b/src/infi/clickhouse_orm/query.py index 010276c..53927a0 100644 --- a/src/infi/clickhouse_orm/query.py +++ b/src/infi/clickhouse_orm/query.py @@ -452,12 +452,24 @@ class QuerySet(object): qs._order_by = field_names return qs - def having(self, having_str): + def having(self, *q, **kwargs): """ - Returns a copy of this queryset with the having changed. + Returns a copy of this queryset that includes only rows matching the having conditions. """ + qs = copy(self) - qs._having = having_str + + condition = Q() + for arg in q: + if isinstance(arg, Q): + condition &= arg + else: + raise TypeError('Invalid argument "%r" to queryset filter' % arg) + + if kwargs: + condition &= Q(**kwargs) + + qs._having = condition.to_sql(self._model_cls) return qs def only(self, *field_names):