diff options
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/gis/db/models/sql/aggregates.py | 6 | ||||
| -rw-r--r-- | django/db/models/sql/aggregates.py | 4 | ||||
| -rw-r--r-- | django/forms/models.py | 6 |
3 files changed, 14 insertions, 2 deletions
diff --git a/django/contrib/gis/db/models/sql/aggregates.py b/django/contrib/gis/db/models/sql/aggregates.py index f8f3ed1eb4..c0a7d894eb 100644 --- a/django/contrib/gis/db/models/sql/aggregates.py +++ b/django/contrib/gis/db/models/sql/aggregates.py @@ -1,7 +1,11 @@ -from django.db.models.sql.aggregates import Aggregate +from django.db.models.sql import aggregates +from django.db.models.sql.aggregates import * # NOQA from django.contrib.gis.db.models.fields import GeometryField +__all__ = ['Collect', 'Extent', 'Extent3D', 'MakeLine', 'Union'] + aggregates.__all__ + + class GeoAggregate(Aggregate): # Default SQL template for spatial aggregates. sql_template = '%(function)s(%(field)s)' diff --git a/django/db/models/sql/aggregates.py b/django/db/models/sql/aggregates.py index 0e1794e0a9..8542a330c6 100644 --- a/django/db/models/sql/aggregates.py +++ b/django/db/models/sql/aggregates.py @@ -5,6 +5,10 @@ import copy from django.db.models.fields import IntegerField, FloatField + +__all__ = ['Aggregate', 'Avg', 'Count', 'Max', 'Min', 'StdDev', 'Sum', 'Variance'] + + # Fake fields used to identify aggregate types in data-conversion operations. ordinal_aggregate_field = IntegerField() computed_aggregate_field = FloatField() diff --git a/django/forms/models.py b/django/forms/models.py index 71da43390c..32f0f043ae 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -134,7 +134,11 @@ def model_to_dict(instance, fields=None, exclude=None): data[f.name] = [] else: # MultipleChoiceWidget needs a list of pks, not object instances. - data[f.name] = list(f.value_from_object(instance).values_list('pk', flat=True)) + qs = f.value_from_object(instance) + if qs._result_cache is not None: + data[f.name] = [item.pk for item in qs] + else: + data[f.name] = list(qs.values_list('pk', flat=True)) else: data[f.name] = f.value_from_object(instance) return data |
