db.models.functions.datetime.Extract

class Extract(expression, lookup_name=None, tzinfo=None, **extra) [source] Extracts a component of a date as a number. Takes an expression representing a DateField or DateTimeField and a lookup_name, and returns the part of the date referenced by lookup_name as an IntegerField. Django usually uses the databases’ extract function, so you may use any lookup_name that your database supports. A tzinfo subclass, usually provided by pytz, can be passed to extract a value in a specific timezone. Gi

db.models.functions.Concat

class Concat(*expressions, **extra) [source] Accepts a list of at least two text fields or expressions and returns the concatenated text. Each argument must be of a text or char type. If you want to concatenate a TextField() with a CharField(), then be sure to tell Django that the output_field should be a TextField(). This is also required when concatenating a Value as in the example below. This function will never have a null result. On backends where a null argument results in the entire e

db.models.functions.Coalesce

class Coalesce(*expressions, **extra) [source] Accepts a list of at least two field names or expressions and returns the first non-null value (note that an empty string is not considered a null value). Each argument must be of a similar type, so mixing text and numbers will result in a database error. Usage examples: >>> # Get a screen name from least to most public >>> from django.db.models import Sum, Value as V >>> from django.db.models.functions import Coalesce

db.models.functions.Cast

class Cast(expression, output_field) [source] New in Django 1.10. Forces the result type of expression to be the one from output_field. Usage example: >>> from django.db.models import FloatField >>> from django.db.models.functions import Cast >>> Value.objects.create(integer=4) >>> value = Value.objects.annotate(as_float=Cast('integer', FloatField())).get() >>> print(value.as_float) 4.0

db.models.Func.template

template A class attribute, as a format string, that describes the SQL that is generated for this function. Defaults to '%(function)s(%(expressions)s)'. If you’re constructing SQL like strftime('%W', 'date') and need a literal % character in the query, quadruple it (%%%%) in the template attribute because the string is interpolated twice: once during the template interpolation in as_sql() and once in the SQL interpolation with the query parameters in the database cursor.

db.models.Func.function

function A class attribute describing the function that will be generated. Specifically, the function will be interpolated as the function placeholder within template. Defaults to None.

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,

db.models.Func.arity

arity New in Django 1.10. A class attribute that denotes the number of arguments the function accepts. If this attribute is set and the function is called with a different number of expressions, TypeError will be raised. Defaults to None.

db.models.Func.arg_joiner

arg_joiner A class attribute that denotes the character used to join the list of expressions together. Defaults to ', '.

db.models.Func

class Func(*expressions, **extra) [source] function A class attribute describing the function that will be generated. Specifically, the function will be interpolated as the function placeholder within template. Defaults to None. template A class attribute, as a format string, that describes the SQL that is generated for this function. Defaults to '%(function)s(%(expressions)s)'. If you’re constructing SQL like strftime('%W', 'date') and need a literal % character in the query, quadr