diff --git a/django/db/models/query.py b/django/db/models/query.py
index 9323e9b..6716dc0 100644
a
|
b
|
class ValuesQuerySet(QuerySet):
|
696 | 696 | # QuerySet.clone() will also set up the _fields attribute with the |
697 | 697 | # names of the model fields to select. |
698 | 698 | |
| 699 | def extra(self, *args, **kwargs): |
| 700 | q = super(ValuesQuerySet, self).extra(*args, **kwargs) |
| 701 | if q.extra_names is not None: |
| 702 | q.query.trim_extra_select(q.extra_names) |
| 703 | return q |
| 704 | |
699 | 705 | def iterator(self): |
700 | 706 | # Purge any extra columns that haven't been explicitly asked for |
701 | 707 | if self.extra_names is not None: |
… |
… |
class ValuesQuerySet(QuerySet):
|
747 | 753 | if self.aggregate_names is not None: |
748 | 754 | self.query.set_aggregate_mask(self.aggregate_names) |
749 | 755 | |
| 756 | if self.extra_names is not None: |
| 757 | self.query.trim_extra_select(self.extra_names) |
| 758 | |
750 | 759 | def _clone(self, klass=None, setup=False, **kwargs): |
751 | 760 | """ |
752 | 761 | Cloning a ValuesQuerySet preserves the current fields. |
diff --git a/tests/regressiontests/extra_regress/models.py b/tests/regressiontests/extra_regress/models.py
index fd34982..121076e 100644
a
|
b
|
class TestObject(models.Model):
|
35 | 35 | second = models.CharField(max_length=20) |
36 | 36 | third = models.CharField(max_length=20) |
37 | 37 | |
| 38 | def __unicode__(self): |
| 39 | return "%s-%s-%s" % (self.first, self.second, self.third) |
| 40 | |
38 | 41 | __test__ = {"API_TESTS": """ |
39 | 42 | # Regression tests for #7314 and #7372 |
40 | 43 | |
… |
… |
True
|
189 | 192 | >>> TestObject.objects.extra(select=SortedDict((('foo','first'),('bar','second'),('whiz','third')))).values_list('whiz', 'first', 'bar', 'id') |
190 | 193 | [(u'third', u'first', u'second', 1)] |
191 | 194 | |
192 | | """} |
| 195 | >>> list(TestObject.objects.filter(pk__in=TestObject.objects.extra(select={'extra': 1}).values('pk'))) == list(TestObject.objects.all()) |
| 196 | True |
| 197 | |
| 198 | >>> TestObject.objects.values('pk').extra(select={'extra': 1}) |
| 199 | [{'pk': 1}] |
193 | 200 | |
| 201 | >>> TestObject.objects.filter(pk__in=TestObject.objects.values('pk').extra(select={'extra': 1})) |
| 202 | [<TestObject: first-second-third>] |
194 | 203 | |
| 204 | """} |