Filtering by Count aggregate does not work when using GeoManager
Reported by: |
David Gouldin |
Owned by: |
jbronn |
Component:
|
GIS
|
Version:
|
dev
|
Severity:
|
|
Keywords:
|
|
Cc:
|
jdunck@…, dgouldin@…
|
Triage Stage:
|
Accepted
|
Has patch:
|
yes
|
Needs documentation:
|
no
|
Needs tests:
|
yes
|
Patch needs improvement:
|
no
|
Easy pickings:
|
no
|
UI/UX:
|
no
|
Using the following models:
from django.contrib.gis.db import models
class Book(models.Model):
name = models.CharField(max_length=100)
objects = models.GeoManager()
class Author(models.Model):
name = models.CharField(max_length=100)
books = models.ForeignKey(Book, related_name="authors")
objects = models.GeoManager()
Filtering on an annotated Count aggregate raises an AttributeError. Example:
>>> from mytestapp.models import Book, Author
>>> from django.db.models import Count
>>> Book.objects.annotate(num_authors=Count('authors')).filter(num_authors__gt=1)
...
<type 'exceptions.AttributeError'>: 'Count' object has no attribute 'alias'
(In [10912]) Fixed #11087 -- Fixed the
Count
annotation when used withGeoManager
. Thanks to dgouldin for ticket and initial patch.