db.models.Field.blank

Field.blank If True, the field is allowed to be blank. Default is False. Note that this is different than null. null is purely database-related, whereas blank is validation-related. If a field has blank=True, form validation will allow entry of an empty value. If a field has blank=False, the field will be required.

db.models.Field.auto_created

Field.auto_created Boolean flag that indicates if the field was automatically created, such as the OneToOneField used by model inheritance.

db.models.Field

class Field [source] Field is an abstract class that represents a database table column. Django uses fields to create the database table (db_type()), to map Python types to database (get_prep_value()) and vice-versa (from_db_value()). A field is thus a fundamental piece in different Django APIs, notably, models and querysets. In models, a field is instantiated as a class attribute and represents a particular table column, see Models. It has attributes such as null and unique, and methods tha

db.models.F

class F [source] An F() object represents the value of a model field or annotated column. It makes it possible to refer to model field values and perform database operations using them without actually having to pull them out of the database into Python memory. Instead, Django uses the F() object to generate an SQL expression that describes the required operation at the database level. This is easiest to understand through an example. Normally, one might do something like this: # Tintin file

db.models.ExpressionWrapper

class ExpressionWrapper(expression, output_field) [source] ExpressionWrapper simply surrounds another expression and provides access to properties, such as output_field, that may not be available on other expressions. ExpressionWrapper is necessary when using arithmetic on F() expressions with different types as described in Using F() with annotations.

db.models.expressions.When

class When(condition=None, then=None, **lookups) [source] A When() object is used to encapsulate a condition and its result for use in the conditional expression. Using a When() object is similar to using the filter() method. The condition can be specified using field lookups or Q objects. The result is provided using the then keyword. Some examples: >>> from django.db.models import When, F, Q >>> # String arguments refer to fields; the following two examples are equivalent

db.models.expressions.RawSQL

class RawSQL(sql, params, output_field=None) [source] Sometimes database expressions can’t easily express a complex WHERE clause. In these edge cases, use the RawSQL expression. For example: >>> from django.db.models.expressions import RawSQL >>> queryset.annotate(val=RawSQL("select col from sometable where othercol = %s", (someparam,))) These extra lookups may not be portable to different database engines (because you’re explicitly writing SQL code) and violate the DRY pr

db.models.expressions.Case

class Case(*cases, **extra) [source] A Case() expression is like the if ... elif ... else statement in Python. Each condition in the provided When() objects is evaluated in order, until one evaluates to a truthful value. The result expression from the matching When() object is returned. A simple example: >>> >>> from datetime import date, timedelta >>> from django.db.models import CharField, Case, Value, When >>> Client.objects.create( ... name='Jane D

db.models.Expression.set_source_expressions()

set_source_expressions(expressions) Takes a list of expressions and stores them such that get_source_expressions() can return them.

db.models.Expression.reverse_ordering()

reverse_ordering() Returns self with any modifications required to reverse the sort order within an order_by call. As an example, an expression implementing NULLS LAST would change its value to be NULLS FIRST. Modifications are only required for expressions that implement sort order like OrderBy. This method is called when reverse() is called on a queryset.