diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-10-15 02:54:30 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-10-15 02:54:30 +0000 |
| commit | 70d5e32e13426372d3d98bb7664d8a69975ed885 (patch) | |
| tree | e9fd2c235a9bf999f97f3a9119c95a5fdcb75246 /django | |
| parent | 4c4341f01289e66f084d295236274a2e4556ae0d (diff) | |
queryset-refactor: Made the use of values() for ForeignKey fields consistent
and documented this feature. Refs #4358.
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6516 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/query.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py index b2ed0d36a7..9a590ddd26 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -391,17 +391,22 @@ class ValuesQuerySet(QuerySet): # 'fields' is used to configure the query, whilst field_names is stored # in this object for use by iterator(). if self._fields: + opts = self.model._meta + all = dict([(field.column, field) for field in opts.fields]) + all.update([(field.name, field) for field in opts.fields]) if not self.query.extra_select: - fields = [self.model._meta.get_field(f, many_to_many=False) - for f in self._fields] + try: + fields = [all[f] for f in self._fields] + except KeyError, e: + raise FieldDoesNotExist('%s has no field named %r' + % (opts.object_name, e.args[0])) field_names = self._fields else: fields = [] field_names = [] for f in self._fields: - if f in [field.name for field in self.model._meta.fields]: - fields.append(self.model._meta.get_field(f, - many_to_many=False)) + if f in all: + fields.append(all[f]) field_names.append(f) elif not self.query.extra_select.has_key(f): raise FieldDoesNotExist('%s has no field named %r' |
