mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
@@ -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)'
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user