Ticket #7231: extra-join.diff
File extra-join.diff, 2.4 KB (added by , 17 years ago) |
---|
-
django/db/models/sql/query.py
82 82 self.extra_where = () 83 83 self.extra_params = () 84 84 self.extra_order_by = () 85 self.extra_join = () 85 86 86 87 def __str__(self): 87 88 """ … … 182 183 obj.extra_where = self.extra_where 183 184 obj.extra_params = self.extra_params 184 185 obj.extra_order_by = self.extra_order_by 186 obj.extra_join = self.extra_join 185 187 obj.__dict__.update(kwargs) 186 188 if hasattr(obj, '_setup_query'): 187 189 obj._setup_query() … … 261 263 result.append('FROM') 262 264 result.extend(from_) 263 265 params.extend(f_params) 266 267 if self.extra_join: 268 result.append(' '.join(self.extra_join)) 264 269 265 270 if where: 266 271 result.append('WHERE %s' % where) … … 1379 1384 self.related_select_cols = [] 1380 1385 self.related_select_fields = [] 1381 1386 1382 def add_extra(self, select, select_params, where, params, tables, order_by ):1387 def add_extra(self, select, select_params, where, params, tables, order_by, join): 1383 1388 """ 1384 1389 Adds data to the various extra_* attributes for user-created additions 1385 1390 to the query. … … 1401 1406 self.extra_tables += tuple(tables) 1402 1407 if order_by: 1403 1408 self.extra_order_by = order_by 1409 if join: 1410 self.extra_join += tuple(join) 1404 1411 1405 1412 def trim_extra_select(self, names): 1406 1413 """ -
django/db/models/query.py
448 448 return obj 449 449 450 450 def extra(self, select=None, where=None, params=None, tables=None, 451 order_by=None, select_params=None ):451 order_by=None, select_params=None, join=None): 452 452 """ 453 453 Add extra SQL fragments to the query. 454 454 """ 455 455 assert self.query.can_filter(), \ 456 456 "Cannot change a query once a slice has been taken" 457 457 clone = self._clone() 458 clone.query.add_extra(select, select_params, where, params, tables, order_by )458 clone.query.add_extra(select, select_params, where, params, tables, order_by, join) 459 459 return clone 460 460 461 461 def reverse(self):