mirror of
https://github.com/jazzband/django-ddp.git
synced 2026-03-26 11:20:22 +00:00
Fix array aggregate for Django 1.8
This commit is contained in:
parent
9b18e4833a
commit
07ccc014bc
1 changed files with 19 additions and 13 deletions
32
dddp/api.py
32
dddp/api.py
|
|
@ -11,11 +11,11 @@ import dbarray
|
|||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import connection, connections
|
||||
from django.db.models import aggregates, Q, Expression
|
||||
from django.db.models import aggregates, Q
|
||||
try:
|
||||
from django.db.models.expressions import ExpressionNode
|
||||
except ImportError:
|
||||
ExpressionNode = None
|
||||
from django.db.models import Expression as ExpressionNode
|
||||
from django.db.models.sql import aggregates as sql_aggregates
|
||||
from django.utils.encoding import force_text
|
||||
from django.db import DatabaseError
|
||||
|
|
@ -51,6 +51,7 @@ class Array(aggregates.Aggregate):
|
|||
"""Array aggregate function."""
|
||||
|
||||
func = 'ARRAY'
|
||||
function = 'array_agg'
|
||||
name = 'Array'
|
||||
|
||||
def add_to_query(self, query, alias, col, source, is_summary):
|
||||
|
|
@ -67,9 +68,17 @@ class Array(aggregates.Aggregate):
|
|||
return 'ArrayType'
|
||||
|
||||
new_source = ArrayField()
|
||||
super(Array, self).add_to_query(
|
||||
query, alias, col, new_source, is_summary,
|
||||
)
|
||||
try:
|
||||
super(Array, self).add_to_query(
|
||||
query, alias, col, new_source, is_summary,
|
||||
)
|
||||
except AttributeError:
|
||||
query.aggregates[alias] = new_source
|
||||
|
||||
def convert_value(self, value, expression, connection, context):
|
||||
if not value:
|
||||
return []
|
||||
return value
|
||||
|
||||
|
||||
def api_endpoint(path_or_func):
|
||||
|
|
@ -356,14 +365,11 @@ class Collection(APIMixin):
|
|||
|
||||
def serialize(self, obj, meteor_ids):
|
||||
"""Generate a DDP msg for obj with specified msg type."""
|
||||
if ExpressionNode is None:
|
||||
exps = False
|
||||
else:
|
||||
# check for F expressions
|
||||
exps = [
|
||||
name for name, val in vars(obj).items()
|
||||
if isinstance(val, ExpressionNode)
|
||||
]
|
||||
# check for F expressions
|
||||
exps = [
|
||||
name for name, val in vars(obj).items()
|
||||
if isinstance(val, ExpressionNode)
|
||||
]
|
||||
if exps:
|
||||
# clone/update obj with values but only for the expression fields
|
||||
obj = deepcopy(obj)
|
||||
|
|
|
|||
Loading…
Reference in a new issue