Ticket #8784: patch.diff
File patch.diff, 3.3 KB (added by , 16 years ago) |
---|
-
django/db/models/sql/query.py
84 84 self.extra_tables = () 85 85 self.extra_where = () 86 86 self.extra_params = () 87 self.extra_having = () 87 88 self.extra_order_by = () 88 89 89 90 def __str__(self): … … 186 187 obj.extra_tables = self.extra_tables 187 188 obj.extra_where = self.extra_where 188 189 obj.extra_params = self.extra_params 190 obj.extra_having = self.extra_having 189 191 obj.extra_order_by = self.extra_order_by 190 192 if self.filter_is_sticky and self.used_aliases: 191 193 obj.used_aliases = self.used_aliases.copy() … … 292 294 grouping = self.get_grouping() 293 295 result.append('GROUP BY %s' % ', '.join(grouping)) 294 296 297 if self.extra_having: 298 result.append('HAVING %s' % self.extra_having[0]) 299 295 300 if ordering: 296 301 result.append('ORDER BY %s' % ', '.join(ordering)) 297 302 … … 388 393 if self.extra_where and rhs.extra_where: 389 394 raise ValueError("When merging querysets using 'or', you " 390 395 "cannot have extra(where=...) on both sides.") 396 if self.extra_having and rhs.extra_having: 397 raise ValueError("When merging querysets using 'or', you " 398 "cannot have extra(having=...) on both sides.") 391 399 self.extra_select.update(rhs.extra_select) 392 400 self.extra_tables += rhs.extra_tables 393 401 self.extra_where += rhs.extra_where 394 402 self.extra_params += rhs.extra_params 403 self.extra_having += rhs.extra_having 395 404 396 405 # Ordering uses the 'rhs' ordering, unless it has none, in which case 397 406 # the current ordering is used. … … 1567 1576 self.related_select_cols = [] 1568 1577 self.related_select_fields = [] 1569 1578 1570 def add_extra(self, select, select_params, where, params, tables, order_by ):1579 def add_extra(self, select, select_params, where, params, tables, order_by, having): 1571 1580 """ 1572 1581 Adds data to the various extra_* attributes for user-created additions 1573 1582 to the query. … … 1598 1607 self.extra_params += tuple(params) 1599 1608 if tables: 1600 1609 self.extra_tables += tuple(tables) 1610 if having: 1611 self.extra_having += tuple(having) 1601 1612 if order_by: 1602 1613 self.extra_order_by = order_by 1603 1614 -
django/db/models/query.py
567 567 return obj 568 568 569 569 def extra(self, select=None, where=None, params=None, tables=None, 570 order_by=None, select_params=None ):570 order_by=None, select_params=None, having=None): 571 571 """ 572 572 Adds extra SQL fragments to the query. 573 573 """ 574 574 assert self.query.can_filter(), \ 575 575 "Cannot change a query once a slice has been taken" 576 576 clone = self._clone() 577 clone.query.add_extra(select, select_params, where, params, tables, order_by )577 clone.query.add_extra(select, select_params, where, params, tables, order_by, having) 578 578 return clone 579 579 580 580 def reverse(self):