-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support having #171
base: develop
Are you sure you want to change the base?
support having #171
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,6 +295,7 @@ def __init__(self, model_cls, database): | |
self._model_cls = model_cls | ||
self._database = database | ||
self._order_by = [] | ||
self._having = '' | ||
self._where_q = Q() | ||
self._prewhere_q = Q() | ||
self._grouping_fields = [] | ||
|
@@ -392,6 +393,9 @@ def as_sql(self): | |
if self._grouping_with_totals: | ||
sql += ' WITH TOTALS' | ||
|
||
if self._having: | ||
sql += '\nhaving ' + self.having_as_sql() | ||
|
||
if self._order_by: | ||
sql += '\nORDER BY ' + self.order_by_as_sql() | ||
|
||
|
@@ -413,6 +417,12 @@ def order_by_as_sql(self): | |
for field in self._order_by | ||
]) | ||
|
||
def having_as_sql(self): | ||
""" | ||
Returns the contents of the query's `Having` clause as a string. | ||
""" | ||
return self._having | ||
|
||
def conditions_as_sql(self, prewhere=False): | ||
""" | ||
Returns the contents of the query's `WHERE` or `PREWHERE` clause as a string. | ||
|
@@ -442,6 +452,14 @@ def order_by(self, *field_names): | |
qs._order_by = field_names | ||
return qs | ||
|
||
def having(self, having_str): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use Q function to support HAVING. Thanks to check it |
||
""" | ||
Returns a copy of this queryset with the having changed. | ||
""" | ||
qs = copy(self) | ||
qs._having = having_str | ||
return qs | ||
|
||
def only(self, *field_names): | ||
""" | ||
Returns a copy of this queryset limited to the specified field names. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it makes sense to use caps i.e.
HAVING
in order to keep the styleThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok,, I change it.