db.models.Func.as_sql()

as_sql(compiler, connection, function=None, template=None, arg_joiner=None, **extra_context) [source]

Generates the SQL for the database function.

The as_vendor() methods should use the function, template, arg_joiner, and any other **extra_context parameters to customize the SQL as needed. For example:

class ConcatPair(Func):
    ...
    function = 'CONCAT'
    ...

    def as_mysql(self, compiler, connection):
        return super(ConcatPair, self).as_sql(
            compiler, connection,
            function='CONCAT_WS',
            template="%(function)s('', %(expressions)s)",
        )
Changed in Django 1.10:

Support for the arg_joiner and **extra_context parameters was added.

doc_Django
2016-10-09 18:35:41
Comments
Leave a Comment

Please login to continue.