0

如果您查看 Django 中聚合函数的定义,您会发现它们实际上是类的子类,django.db.models.aggregates.Aggregate它们的构造函数如下所示:

class Aggregate(object):
"""
Default Aggregate definition.
"""
def __init__(self, lookup, **extra):
    """Instantiate a new aggregate.

     * lookup is the field on which the aggregate operates.
     * extra is a dictionary of additional data to provide for the
       aggregate definition

    Also utilizes the class variables:
     * name, the identifier for this aggregate function.
    """
    self.lookup = lookup
    self.extra = extra

    #... the rest is truncated

这个额外的关键字参数用于什么?我可以使用它们对聚合进行更复杂的查询吗?我试图在上面找到任何文档,但没有成功。我相信它没有记录在案,但无论如何,这些额外的论点是什么,可以用它们做什么?

谢谢。

4

1 回答 1

0

当然,

只需查看源代码,extra即可将其解包并传递给“后端特定”聚合类

后端的后端特定聚合SQL位于db.models.sql.aggregates.

在那里,您会看到Sum接受一个distinct参数,StdDevVariance接受一个sample参数。

于 2013-10-20T16:31:06.550 回答