Ticket #11890: query.py

File query.py, 1.7 KB (added by jaklaassen@…, 15 years ago)

django.db.models.query.py

Line 
1def results_iter(self):
2 """
3 Returns an iterator over the results from executing this query.
4 """
5 resolve_columns = hasattr(self, 'resolve_columns')
6 fields = None
7
8 if self.aggregate_select:
9 aggregate_start = len(self.extra_select.keys())
10 only_load = self.deferred_to_columns()
11 for col in self.select:
12 if isinstance(col, (list, tuple)):
13 alias, column = col
14 table = self.alias_map[alias][TABLE_NAME]
15 if table not in only_load or column in only_load[table]:
16 aggregate_start += 1
17 aggregate_end = aggregate_start + len(self.aggregate_select)
18
19 for rows in self.execute_sql(MULTI):
20 for row in rows:
21 if resolve_columns:
22 if fields is None:
23 # We only set this up here because
24 # related_select_fields isn't populated until
25 # execute_sql() has been called.
26 if self.select_fields:
27 fields = self.select_fields + self.related_select_fields
28 else:
29 fields = self.model._meta.fields
30 row = self.resolve_columns(row, fields)
31
32 if self.aggregate_select:
33 row = tuple(row[:aggregate_start]) + tuple([
34 self.resolve_aggregate(value, aggregate)
35 for (alias, aggregate), value
36 in zip(self.aggregate_select.items(), row[aggregate_start:aggregate_end])
37 ]) + tuple(row[aggregate_end:])
38 yield row
Back to Top