Ticket #22057: 22057.diff

File 22057.diff, 1.6 KB (added by Claude Paroz, 10 years ago)

Removed import time instanciations in django/db/models/sql/aggregates.py

  • django/db/models/sql/aggregates.py

    diff --git a/django/db/models/sql/aggregates.py b/django/db/models/sql/aggregates.py
    index aef8b49..ce2968c 100644
    a b import copy  
    55
    66from django.db.models.fields import IntegerField, FloatField
    77from django.db.models.lookups import RegisterLookupMixin
     8from django.utils.functional import cached_property
    89
    910
    1011__all__ = ['Aggregate', 'Avg', 'Count', 'Max', 'Min', 'StdDev', 'Sum', 'Variance']
    1112
    1213
    13 # Fake fields used to identify aggregate types in data-conversion operations.
    14 ordinal_aggregate_field = IntegerField()
    15 computed_aggregate_field = FloatField()
    16 
    17 
    1814class Aggregate(RegisterLookupMixin):
    1915    """
    2016    Default SQL Aggregate.
    class Aggregate(RegisterLookupMixin):  
    6157
    6258        while tmp and isinstance(tmp, Aggregate):
    6359            if getattr(tmp, 'is_ordinal', False):
    64                 tmp = ordinal_aggregate_field
     60                tmp = self._ordinal_aggregate_field
    6561            elif getattr(tmp, 'is_computed', False):
    66                 tmp = computed_aggregate_field
     62                tmp = self._computed_aggregate_field
    6763            else:
    6864                tmp = tmp.source
    6965
    7066        self.field = tmp
    7167
     68    # Two fake fields used to identify aggregate types in data-conversion operations.
     69    @cached_property
     70    def _ordinal_aggregate_field(self):
     71        return IntegerField()
     72
     73    @cached_property
     74    def _computed_aggregate_field(self):
     75        return FloatField()
     76
    7277    def relabeled_clone(self, change_map):
    7378        clone = copy.copy(self)
    7479        if isinstance(self.col, (list, tuple)):
Back to Top