              Author.objects.annotate(c=Count("friends__name")).exclude(friends__name="Joe").count(),
              Author.objects.count()
          )
  
      @skipUnlessDBFeature('supports_stddev')
      def test_stddev(self):
          self.assertEqual(
              Book.objects.aggregate(StdDev('pages')),
              {'pages__stddev': Approximate(311.46, 1)}
 
</s> remove         out = pickle.dumps(qs)
 </s> add         pickle.dumps(qs) </s> remove             self.cols[node] = (change_map.get(col[0], col[0]), col[1])
 </s> add             if hasattr(col, "relabel_aliases"):
                col.relabel_aliases(change_map)
            else:
                self.cols[node] = (change_map.get(col[0], col[0]), col[1]) </s> remove from regressiontests.aggregation_regress.models import *
 </s> add from models import Author, Book, Publisher, Clues, Entries, HardbackBook </s> remove from django.db import DEFAULT_DB_ALIAS
 </s> add  </s> remove from django.conf import settings
 </s> add 
    def test_f_expression_annotation(self):
        # Books with less than 200 pages per author.
        qs = Book.objects.values("name").annotate(
            n_authors=Count("authors")
        ).filter(
            pages__lt=F("n_authors") * 200
        ).values_list("pk")
        self.assertQuerysetEqual(
            Book.objects.filter(pk__in=qs), [
                "Python Web Development with Django"
            ],
            attrgetter("name")
        )

              Author.objects.annotate(c=Count("friends__name")).exclude(friends__name="Joe").count(),
              Author.objects.count()
          )
  
    def test_f_expression_annotation(self):
        # Books with less than 200 pages per author.
        qs = Book.objects.values("name").annotate(
            n_authors=Count("authors")
        ).filter(
            pages__lt=F("n_authors") * 200
        ).values_list("pk")
        self.assertQuerysetEqual(
            Book.objects.filter(pk__in=qs), [
                "Python Web Development with Django"
            ],
            attrgetter("name")
        )

      @skipUnlessDBFeature('supports_stddev')
      def test_stddev(self):
          self.assertEqual(
              Book.objects.aggregate(StdDev('pages')),
              {'pages__stddev': Approximate(311.46, 1)}
keep keep keep add keep keep keep keep keep
 Fixed #14754 -- corrected using an aggregate in an F expressions when that queryset is later used in a subquery.  Thanks to master for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14681 bcc190cf-cafb-0310-a4f2-bffc1f526a37 
tests/regressiontests/aggregation_regress/tests.py