doc_content
stringlengths
1
386k
doc_id
stringlengths
5
188
Index.condition
django.ref.models.indexes#django.db.models.Index.condition
Index.db_tablespace
django.ref.models.indexes#django.db.models.Index.db_tablespace
Index.expressions
django.ref.models.indexes#django.db.models.Index.expressions
Index.fields
django.ref.models.indexes#django.db.models.Index.fields
Index.include
django.ref.models.indexes#django.db.models.Index.include
Index.name
django.ref.models.indexes#django.db.models.Index.name
Index.opclasses
django.ref.models.indexes#django.db.models.Index.opclasses
class IntegerField(**options)
django.ref.models.fields#django.db.models.IntegerField
class JSONField(encoder=None, decoder=None, **options)
django.ref.models.fields#django.db.models.JSONField
JSONField.decoder An optional json.JSONDecoder subclass to deserialize the value retrieved from the database. The value will be in the format chosen by the custom encoder (most often a string). Your deserialization may need to account for the fact that you can’t be certain of the input type. For example, you run the ...
django.ref.models.fields#django.db.models.JSONField.decoder
JSONField.encoder An optional json.JSONEncoder subclass to serialize data types not supported by the standard JSON serializer (e.g. datetime.datetime or UUID). For example, you can use the DjangoJSONEncoder class. Defaults to json.JSONEncoder.
django.ref.models.fields#django.db.models.JSONField.encoder
class Lookup A Lookup is a generic class to implement lookups. A lookup is a query expression with a left-hand side, lhs; a right-hand side, rhs; and a lookup_name that is used to produce a boolean comparison between lhs and rhs such as lhs in rhs or lhs > rhs. The primary notation to use a lookup in an expression is...
django.ref.models.lookups#django.db.models.Lookup
lhs The left-hand side - what is being looked up. The object typically follows the Query Expression API. It may also be a plain value.
django.ref.models.lookups#django.db.models.Lookup.lhs
lookup_name The name of this lookup, used to identify it on parsing query expressions. It cannot contain the string "__".
django.ref.models.lookups#django.db.models.Lookup.lookup_name
process_lhs(compiler, connection, lhs=None) Returns a tuple (lhs_string, lhs_params), as returned by compiler.compile(lhs). This method can be overridden to tune how the lhs is processed. compiler is an SQLCompiler object, to be used like compiler.compile(lhs) for compiling lhs. The connection can be used for compili...
django.ref.models.lookups#django.db.models.Lookup.process_lhs
process_rhs(compiler, connection) Behaves the same way as process_lhs(), for the right-hand side.
django.ref.models.lookups#django.db.models.Lookup.process_rhs
rhs The right-hand side - what lhs is being compared against. It can be a plain value, or something that compiles into SQL, typically an F() object or a QuerySet.
django.ref.models.lookups#django.db.models.Lookup.rhs
class lookups.RegisterLookupMixin A mixin that implements the lookup API on a class. classmethod register_lookup(lookup, lookup_name=None) Registers a new lookup in the class. For example DateField.register_lookup(YearExact) will register YearExact lookup on DateField. It overrides a lookup that already exists wi...
django.ref.models.lookups#django.db.models.lookups.RegisterLookupMixin
get_lookup(lookup_name) Returns the Lookup named lookup_name registered in the class. The default implementation looks recursively on all parent classes and checks if any has a registered lookup named lookup_name, returning the first match.
django.ref.models.lookups#django.db.models.lookups.RegisterLookupMixin.get_lookup
get_lookups() Returns a dictionary of each lookup name registered in the class mapped to the Lookup class.
django.ref.models.lookups#django.db.models.lookups.RegisterLookupMixin.get_lookups
get_transform(transform_name) Returns a Transform named transform_name. The default implementation looks recursively on all parent classes to check if any has the registered transform named transform_name, returning the first match.
django.ref.models.lookups#django.db.models.lookups.RegisterLookupMixin.get_transform
class Manager
django.topics.db.managers#django.db.models.Manager
Manager.raw(raw_query, params=(), translations=None)
django.topics.db.sql#django.db.models.Manager.raw
class ManyToManyField(to, **options)
django.ref.models.fields#django.db.models.ManyToManyField
ManyToManyField.db_constraint Controls whether or not constraints should be created in the database for the foreign keys in the intermediary table. The default is True, and that’s almost certainly what you want; setting this to False can be very bad for data integrity. That said, here are some scenarios where you mig...
django.ref.models.fields#django.db.models.ManyToManyField.db_constraint
ManyToManyField.db_table The name of the table to create for storing the many-to-many data. If this is not provided, Django will assume a default name based upon the names of: the table for the model defining the relationship and the name of the field itself.
django.ref.models.fields#django.db.models.ManyToManyField.db_table
ManyToManyField.limit_choices_to Same as ForeignKey.limit_choices_to.
django.ref.models.fields#django.db.models.ManyToManyField.limit_choices_to
ManyToManyField.related_name Same as ForeignKey.related_name.
django.ref.models.fields#django.db.models.ManyToManyField.related_name
ManyToManyField.related_query_name Same as ForeignKey.related_query_name.
django.ref.models.fields#django.db.models.ManyToManyField.related_query_name
ManyToManyField.swappable Controls the migration framework’s reaction if this ManyToManyField is pointing at a swappable model. If it is True - the default - then if the ManyToManyField is pointing at a model which matches the current value of settings.AUTH_USER_MODEL (or another swappable model setting) the relation...
django.ref.models.fields#django.db.models.ManyToManyField.swappable
ManyToManyField.symmetrical Only used in the definition of ManyToManyFields on self. Consider the following model: from django.db import models class Person(models.Model): friends = models.ManyToManyField("self") When Django processes this model, it identifies that it has a ManyToManyField on itself, and as a r...
django.ref.models.fields#django.db.models.ManyToManyField.symmetrical
ManyToManyField.through Django will automatically generate a table to manage many-to-many relationships. However, if you want to manually specify the intermediary table, you can use the through option to specify the Django model that represents the intermediate table that you want to use. The most common use for this...
django.ref.models.fields#django.db.models.ManyToManyField.through
ManyToManyField.through_fields Only used when a custom intermediary model is specified. Django will normally determine which fields of the intermediary model to use in order to establish a many-to-many relationship automatically. However, consider the following models: from django.db import models class Person(model...
django.ref.models.fields#django.db.models.ManyToManyField.through_fields
class Max(expression, output_field=None, filter=None, default=None, **extra) Returns the maximum value of the given expression. Default alias: <field>__max Return type: same as input field, or output_field if supplied
django.ref.models.querysets#django.db.models.Max
class Min(expression, output_field=None, filter=None, default=None, **extra) Returns the minimum value of the given expression. Default alias: <field>__min Return type: same as input field, or output_field if supplied
django.ref.models.querysets#django.db.models.Min
class Model(**kwargs)
django.ref.models.instances#django.db.models.Model
Model.__eq__()
django.ref.models.instances#django.db.models.Model.__eq__
Model.__hash__()
django.ref.models.instances#django.db.models.Model.__hash__
Model.__str__()
django.ref.models.instances#django.db.models.Model.__str__
Model._base_manager
django.topics.db.managers#django.db.models.Model._base_manager
Model._default_manager
django.topics.db.managers#django.db.models.Model._default_manager
Model._state The _state attribute refers to a ModelState object that tracks the lifecycle of the model instance. The ModelState object has two attributes: adding, a flag which is True if the model has not been saved to the database yet, and db, a string referring to the database alias the instance was loaded from or ...
django.ref.models.instances#django.db.models.Model._state
Model.clean()
django.ref.models.instances#django.db.models.Model.clean
Model.clean_fields(exclude=None)
django.ref.models.instances#django.db.models.Model.clean_fields
Model.delete(using=DEFAULT_DB_ALIAS, keep_parents=False)
django.ref.models.instances#django.db.models.Model.delete
Model.full_clean(exclude=None, validate_unique=True)
django.ref.models.instances#django.db.models.Model.full_clean
Model.get_absolute_url()
django.ref.models.instances#django.db.models.Model.get_absolute_url
Model.get_deferred_fields()
django.ref.models.instances#django.db.models.Model.get_deferred_fields
Model.get_FOO_display()
django.ref.models.instances#django.db.models.Model.get_FOO_display
Model.get_next_by_FOO(**kwargs)
django.ref.models.instances#django.db.models.Model.get_next_by_FOO
Model.get_previous_by_FOO(**kwargs)
django.ref.models.instances#django.db.models.Model.get_previous_by_FOO
Model.objects Each non-abstract Model class must have a Manager instance added to it. Django ensures that in your model class you have at least a default Manager specified. If you don’t add your own Manager, Django will add an attribute objects containing default Manager instance. If you add your own Manager instance...
django.ref.models.class#django.db.models.Model.objects
Model.pk
django.ref.models.instances#django.db.models.Model.pk
Model.refresh_from_db(using=None, fields=None)
django.ref.models.instances#django.db.models.Model.refresh_from_db
Model.save(force_insert=False, force_update=False, using=DEFAULT_DB_ALIAS, update_fields=None)
django.ref.models.instances#django.db.models.Model.save
Model.validate_unique(exclude=None)
django.ref.models.instances#django.db.models.Model.validate_unique
class OneToOneField(to, on_delete, parent_link=False, **options)
django.ref.models.fields#django.db.models.OneToOneField
OneToOneField.parent_link When True and used in a model which inherits from another concrete model, indicates that this field should be used as the link back to the parent class, rather than the extra OneToOneField which would normally be implicitly created by subclassing.
django.ref.models.fields#django.db.models.OneToOneField.parent_link
Options.abstract If abstract = True, this model will be an abstract base class.
django.ref.models.options#django.db.models.Options.abstract
Options.app_label If a model is defined outside of an application in INSTALLED_APPS, it must declare which app it belongs to: app_label = 'myapp' If you want to represent a model with the format app_label.object_name or app_label.model_name you can use model._meta.label or model._meta.label_lower respectively.
django.ref.models.options#django.db.models.Options.app_label
Options.base_manager_name The attribute name of the manager, for example, 'objects', to use for the model’s _base_manager.
django.ref.models.options#django.db.models.Options.base_manager_name
Options.constraints A list of constraints that you want to define on the model: from django.db import models class Customer(models.Model): age = models.IntegerField() class Meta: constraints = [ models.CheckConstraint(check=models.Q(age__gte=18), name='age_gte_18'), ]
django.ref.models.options#django.db.models.Options.constraints
Options.db_table The name of the database table to use for the model: db_table = 'music_album'
django.ref.models.options#django.db.models.Options.db_table
Options.db_tablespace The name of the database tablespace to use for this model. The default is the project’s DEFAULT_TABLESPACE setting, if set. If the backend doesn’t support tablespaces, this option is ignored.
django.ref.models.options#django.db.models.Options.db_tablespace
Options.default_manager_name The name of the manager to use for the model’s _default_manager.
django.ref.models.options#django.db.models.Options.default_manager_name
Options.default_permissions Defaults to ('add', 'change', 'delete', 'view'). You may customize this list, for example, by setting this to an empty list if your app doesn’t require any of the default permissions. It must be specified on the model before the model is created by migrate in order to prevent any omitted p...
django.ref.models.options#django.db.models.Options.default_permissions
Options.default_related_name The name that will be used by default for the relation from a related object back to this one. The default is <model_name>_set. This option also sets related_query_name. As the reverse name for a field should be unique, be careful if you intend to subclass your model. To work around name ...
django.ref.models.options#django.db.models.Options.default_related_name
Options.get_latest_by The name of a field or a list of field names in the model, typically DateField, DateTimeField, or IntegerField. This specifies the default field(s) to use in your model Manager’s latest() and earliest() methods. Example: # Latest by ascending order_date. get_latest_by = "order_date" # Latest by...
django.ref.models.options#django.db.models.Options.get_latest_by
Options.index_together Use the indexes option instead. The newer indexes option provides more functionality than index_together. index_together may be deprecated in the future. Sets of field names that, taken together, are indexed: index_together = [ ["pub_date", "deadline"], ] This list of fields will be inde...
django.ref.models.options#django.db.models.Options.index_together
Options.indexes A list of indexes that you want to define on the model: from django.db import models class Customer(models.Model): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) class Meta: indexes = [ models.Index(fields=['last_name', 'fir...
django.ref.models.options#django.db.models.Options.indexes
Options.label Representation of the object, returns app_label.object_name, e.g. 'polls.Question'.
django.ref.models.options#django.db.models.Options.label
Options.label_lower Representation of the model, returns app_label.model_name, e.g. 'polls.question'.
django.ref.models.options#django.db.models.Options.label_lower
Options.managed Defaults to True, meaning Django will create the appropriate database tables in migrate or as part of migrations and remove them as part of a flush management command. That is, Django manages the database tables’ lifecycles. If False, no database table creation, modification, or deletion operations wi...
django.ref.models.options#django.db.models.Options.managed
class Options
django.ref.models.meta#django.db.models.options.Options
Options.get_field(field_name) Returns the field instance given a name of a field. field_name can be the name of a field on the model, a field on an abstract or inherited model, or a field defined on another model that points to the model. In the latter case, the field_name will be (in order of preference) the related...
django.ref.models.meta#django.db.models.options.Options.get_field
Options.get_fields(include_parents=True, include_hidden=False) Returns a tuple of fields associated with a model. get_fields() accepts two parameters that can be used to control which fields are returned: include_parents True by default. Recursively includes fields defined on parent classes. If set to False, get_...
django.ref.models.meta#django.db.models.options.Options.get_fields
Options.order_with_respect_to Makes this object orderable with respect to the given field, usually a ForeignKey. This can be used to make related objects orderable with respect to a parent object. For example, if an Answer relates to a Question object, and a question has more than one answer, and the order of answers...
django.ref.models.options#django.db.models.Options.order_with_respect_to
Options.ordering The default ordering for the object, for use when obtaining lists of objects: ordering = ['-order_date'] This is a tuple or list of strings and/or query expressions. Each string is a field name with an optional “-” prefix, which indicates descending order. Fields without a leading “-” will be ordere...
django.ref.models.options#django.db.models.Options.ordering
Options.permissions Extra permissions to enter into the permissions table when creating this object. Add, change, delete, and view permissions are automatically created for each model. This example specifies an extra permission, can_deliver_pizzas: permissions = [('can_deliver_pizzas', 'Can deliver pizzas')] This is...
django.ref.models.options#django.db.models.Options.permissions
Options.proxy If proxy = True, a model which subclasses another model will be treated as a proxy model.
django.ref.models.options#django.db.models.Options.proxy
Options.required_db_features List of database features that the current connection should have so that the model is considered during the migration phase. For example, if you set this list to ['gis_enabled'], the model will only be synchronized on GIS-enabled databases. It’s also useful to skip some models when testi...
django.ref.models.options#django.db.models.Options.required_db_features
Options.required_db_vendor Name of a supported database vendor that this model is specific to. Current built-in vendor names are: sqlite, postgresql, mysql, oracle. If this attribute is not empty and the current connection vendor doesn’t match it, the model will not be synchronized.
django.ref.models.options#django.db.models.Options.required_db_vendor
Options.select_on_save Determines if Django will use the pre-1.6 django.db.models.Model.save() algorithm. The old algorithm uses SELECT to determine if there is an existing row to be updated. The new algorithm tries an UPDATE directly. In some rare cases the UPDATE of an existing row isn’t visible to Django. An examp...
django.ref.models.options#django.db.models.Options.select_on_save
Options.unique_together Use UniqueConstraint with the constraints option instead. UniqueConstraint provides more functionality than unique_together. unique_together may be deprecated in the future. Sets of field names that, taken together, must be unique: unique_together = [['driver', 'restaurant']] This is a list...
django.ref.models.options#django.db.models.Options.unique_together
Options.verbose_name A human-readable name for the object, singular: verbose_name = "pizza" If this isn’t given, Django will use a munged version of the class name: CamelCase becomes camel case.
django.ref.models.options#django.db.models.Options.verbose_name
Options.verbose_name_plural The plural name for the object: verbose_name_plural = "stories" If this isn’t given, Django will use verbose_name + "s".
django.ref.models.options#django.db.models.Options.verbose_name_plural
class OuterRef(field)
django.ref.models.expressions#django.db.models.OuterRef
output_field Defines the type of class returned by the get_lookup() method. It must be a Field instance.
django.ref.models.lookups#django.db.models.output_field
class PositiveBigIntegerField(**options)
django.ref.models.fields#django.db.models.PositiveBigIntegerField
class PositiveIntegerField(**options)
django.ref.models.fields#django.db.models.PositiveIntegerField
class PositiveSmallIntegerField(**options)
django.ref.models.fields#django.db.models.PositiveSmallIntegerField
class Prefetch(lookup, queryset=None, to_attr=None)
django.ref.models.querysets#django.db.models.Prefetch
prefetch_related_objects(model_instances, *related_lookups)
django.ref.models.querysets#django.db.models.prefetch_related_objects
PROTECT Prevent deletion of the referenced object by raising ProtectedError, a subclass of django.db.IntegrityError.
django.ref.models.fields#django.db.models.PROTECT
class Q
django.ref.models.querysets#django.db.models.Q
class QuerySet(model=None, query=None, using=None, hints=None) Usually when you’ll interact with a QuerySet you’ll use it by chaining filters. To make this work, most QuerySet methods return new querysets. These methods are covered in detail later in this section. The QuerySet class has two public attributes you can ...
django.ref.models.querysets#django.db.models.query.QuerySet
aggregate(*args, **kwargs)
django.ref.models.querysets#django.db.models.query.QuerySet.aggregate
alias(*args, **kwargs)
django.ref.models.querysets#django.db.models.query.QuerySet.alias
all()
django.ref.models.querysets#django.db.models.query.QuerySet.all
annotate(*args, **kwargs)
django.ref.models.querysets#django.db.models.query.QuerySet.annotate