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 risk of returning a datetime that was actually a string that just happened to be in the same format chosen for datetimes. Defaults to json.JSONDecoder. | 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 <lhs>__<lookup_name>=<rhs>. Lookups can also be used directly in QuerySet filters: Book.objects.filter(LessThan(F('word_count'), 7500))
…or annotations: Book.objects.annotate(is_short_story=LessThan(F('word_count'), 7500))
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.
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.
lookup_name
The name of this lookup, used to identify it on parsing query expressions. It cannot contain the string "__".
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 compiling vendor specific SQL. If lhs is not None, use it as the processed lhs instead of self.lhs.
process_rhs(compiler, connection)
Behaves the same way as process_lhs(), for the right-hand side.
Changed in Django 4.0: Support for using lookups in QuerySet annotations, aggregations, and directly in filters was added. | 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 compiling vendor specific SQL. If lhs is not None, use it as the processed lhs instead of self.lhs. | 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 with the same name. lookup_name will be used for this lookup if provided, otherwise lookup.lookup_name will be used.
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.
get_lookups()
Returns a dictionary of each lookup name registered in the class mapped to the Lookup class.
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_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 might want to do this: You have legacy data that is not valid. You’re sharding your database. It is an error to pass both db_constraint and through. | 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 relationship will be stored in the migration using a reference to the setting, not to the model directly. You only want to override this to be False if you are sure your model should always point toward the swapped-in model - for example, if it is a profile model designed specifically for your custom user model. If in doubt, leave it to its default of True. | 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 result, it doesn’t add a person_set attribute to the Person class. Instead, the ManyToManyField is assumed to be symmetrical – that is, if I am your friend, then you are my friend. If you do not want symmetry in many-to-many relationships with self, set symmetrical to False. This will force Django to add the descriptor for the reverse relationship, allowing ManyToManyField relationships to be non-symmetrical. | 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 option is when you want to associate extra data with a many-to-many relationship. Note If you don’t want multiple associations between the same instances, add a UniqueConstraint including the from and to fields. Django’s automatically generated many-to-many tables include such a constraint. Note Recursive relationships using an intermediary model can’t determine the reverse accessors names, as they would be the same. You need to set a related_name to at least one of them. If you’d prefer Django not to create a backwards relation, set related_name to '+'. If you don’t specify an explicit through model, there is still an implicit through model class you can use to directly access the table created to hold the association. It has three fields to link the models. If the source and target models differ, the following fields are generated:
id: the primary key of the relation.
<containing_model>_id: the id of the model that declares the ManyToManyField.
<other_model>_id: the id of the model that the ManyToManyField points to. If the ManyToManyField points from and to the same model, the following fields are generated:
id: the primary key of the relation.
from_<model>_id: the id of the instance which points at the model (i.e. the source instance).
to_<model>_id: the id of the instance to which the relationship points (i.e. the target model instance). This class can be used to query associated records for a given model instance like a normal model: Model.m2mfield.through.objects.all() | 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(models.Model):
name = models.CharField(max_length=50)
class Group(models.Model):
name = models.CharField(max_length=128)
members = models.ManyToManyField(
Person,
through='Membership',
through_fields=('group', 'person'),
)
class Membership(models.Model):
group = models.ForeignKey(Group, on_delete=models.CASCADE)
person = models.ForeignKey(Person, on_delete=models.CASCADE)
inviter = models.ForeignKey(
Person,
on_delete=models.CASCADE,
related_name="membership_invites",
)
invite_reason = models.CharField(max_length=64)
Membership has two foreign keys to Person (person and inviter), which makes the relationship ambiguous and Django can’t know which one to use. In this case, you must explicitly specify which foreign keys Django should use using through_fields, as in the example above. through_fields accepts a 2-tuple ('field1', 'field2'), where field1 is the name of the foreign key to the model the ManyToManyField is defined on (group in this case), and field2 the name of the foreign key to the target model (person in this case). When you have more than one foreign key on an intermediary model to any (or even both) of the models participating in a many-to-many relationship, you must specify through_fields. This also applies to recursive relationships when an intermediary model is used and there are more than two foreign keys to the model, or you want to explicitly specify which two Django should use. | 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 saved to. Newly instantiated instances have adding=True and db=None, since they are yet to be saved. Instances fetched from a QuerySet will have adding=False and db set to the alias of the associated database. | 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 attribute, the default one does not appear. Consider the following example: from django.db import models
class Person(models.Model):
# Add manager with another name
people = models.Manager()
For more details on model managers see Managers and Retrieving objects. | 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 permissions from being created. | 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 collisions, part of the name should contain '%(app_label)s' and '%(model_name)s', which are replaced respectively by the name of the application the model is in, and the name of the model, both lowercased. See the paragraph on related names for abstract models. | 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 priority descending, order_date ascending.
get_latest_by = ['-priority', 'order_date']
See the latest() docs for more. | 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 indexed together (i.e. the appropriate CREATE INDEX statement will be issued.) For convenience, index_together can be a single list when dealing with a single set of fields: index_together = ["pub_date", "deadline"] | 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', 'first_name']),
models.Index(fields=['first_name'], name='first_name_idx'),
] | 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 will be performed for this model. This is useful if the model represents an existing table or a database view that has been created by some other means. This is the only difference when managed=False. All other aspects of model handling are exactly the same as normal. This includes Adding an automatic primary key field to the model if you don’t declare it. To avoid confusion for later code readers, it’s recommended to specify all the columns from the database table you are modeling when using unmanaged models.
If a model with managed=False contains a ManyToManyField that points to another unmanaged model, then the intermediate table for the many-to-many join will also not be created. However, the intermediary table between one managed and one unmanaged model will be created. If you need to change this default behavior, create the intermediary table as an explicit model (with managed set as needed) and use the ManyToManyField.through attribute to make the relation use your custom model. For tests involving models with managed=False, it’s up to you to ensure the correct tables are created as part of the test setup. If you’re interested in changing the Python-level behavior of a model class, you could use managed=False and create a copy of an existing model. However, there’s a better approach for that situation: Proxy models. | 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_query_name set by the user, the related_name set by the user, or the name automatically generated by Django. Hidden fields cannot be retrieved by name. If a field with the given name is not found a FieldDoesNotExist exception will be raised. >>> from django.contrib.auth.models import User
# A field on the model
>>> User._meta.get_field('username')
<django.db.models.fields.CharField: username>
# A field from another model that has a relation with the current model
>>> User._meta.get_field('logentry')
<ManyToOneRel: admin.logentry>
# A non existent field
>>> User._meta.get_field('does_not_exist')
Traceback (most recent call last):
...
FieldDoesNotExist: User has no field named 'does_not_exist' | 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_fields() will only search for fields declared directly on the current model. Fields from models that directly inherit from abstract models or proxy classes are considered to be local, not on the parent.
include_hidden
False by default. If set to True, get_fields() will include fields that are used to back other field’s functionality. This will also include any fields that have a related_name (such as ManyToManyField, or ForeignKey) that start with a “+”. >>> from django.contrib.auth.models import User
>>> User._meta.get_fields()
(<ManyToOneRel: admin.logentry>,
<django.db.models.fields.AutoField: id>,
<django.db.models.fields.CharField: password>,
<django.db.models.fields.DateTimeField: last_login>,
<django.db.models.fields.BooleanField: is_superuser>,
<django.db.models.fields.CharField: username>,
<django.db.models.fields.CharField: first_name>,
<django.db.models.fields.CharField: last_name>,
<django.db.models.fields.EmailField: email>,
<django.db.models.fields.BooleanField: is_staff>,
<django.db.models.fields.BooleanField: is_active>,
<django.db.models.fields.DateTimeField: date_joined>,
<django.db.models.fields.related.ManyToManyField: groups>,
<django.db.models.fields.related.ManyToManyField: user_permissions>)
# Also include hidden fields.
>>> User._meta.get_fields(include_hidden=True)
(<ManyToOneRel: auth.user_groups>,
<ManyToOneRel: auth.user_user_permissions>,
<ManyToOneRel: admin.logentry>,
<django.db.models.fields.AutoField: id>,
<django.db.models.fields.CharField: password>,
<django.db.models.fields.DateTimeField: last_login>,
<django.db.models.fields.BooleanField: is_superuser>,
<django.db.models.fields.CharField: username>,
<django.db.models.fields.CharField: first_name>,
<django.db.models.fields.CharField: last_name>,
<django.db.models.fields.EmailField: email>,
<django.db.models.fields.BooleanField: is_staff>,
<django.db.models.fields.BooleanField: is_active>,
<django.db.models.fields.DateTimeField: date_joined>,
<django.db.models.fields.related.ManyToManyField: groups>,
<django.db.models.fields.related.ManyToManyField: user_permissions>) | 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 matters, you’d do this: from django.db import models
class Question(models.Model):
text = models.TextField()
# ...
class Answer(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
# ...
class Meta:
order_with_respect_to = 'question'
When order_with_respect_to is set, two additional methods are provided to retrieve and to set the order of the related objects: get_RELATED_order() and set_RELATED_order(), where RELATED is the lowercased model name. For example, assuming that a Question object has multiple related Answer objects, the list returned contains the primary keys of the related Answer objects: >>> question = Question.objects.get(id=1)
>>> question.get_answer_order()
[1, 2, 3]
The order of a Question object’s related Answer objects can be set by passing in a list of Answer primary keys: >>> question.set_answer_order([3, 1, 2])
The related objects also get two methods, get_next_in_order() and get_previous_in_order(), which can be used to access those objects in their proper order. Assuming the Answer objects are ordered by id: >>> answer = Answer.objects.get(id=2)
>>> answer.get_next_in_order()
<Answer: 3>
>>> answer.get_previous_in_order()
<Answer: 1> | 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 ordered ascending. Use the string “?” to order randomly. For example, to order by a pub_date field ascending, use this: ordering = ['pub_date']
To order by pub_date descending, use this: ordering = ['-pub_date']
To order by pub_date descending, then by author ascending, use this: ordering = ['-pub_date', 'author']
You can also use query expressions. To order by author ascending and make null values sort last, use this: from django.db.models import F
ordering = [F('author').asc(nulls_last=True)] | 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 a list or tuple of 2-tuples in the format (permission_code,
human_readable_permission_name). | 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 testing with several database backends. Avoid relations between models that may or may not be created as the ORM doesn’t handle this. | 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 example is the PostgreSQL ON UPDATE trigger which returns NULL. In such cases the new algorithm will end up doing an INSERT even when a row exists in the database. Usually there is no need to set this attribute. The default is False. See django.db.models.Model.save() for more about the old and new saving algorithm. | 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 of lists that must be unique when considered together. It’s used in the Django admin and is enforced at the database level (i.e., the appropriate UNIQUE statements are included in the CREATE TABLE statement). For convenience, unique_together can be a single list when dealing with a single set of fields: unique_together = ['driver', 'restaurant']
A ManyToManyField cannot be included in unique_together. (It’s not clear what that would even mean!) If you need to validate uniqueness related to a ManyToManyField, try using a signal or an explicit through model. The ValidationError raised during model validation when the constraint is violated has the unique_together error code. | 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 use for introspection:
ordered
True if the QuerySet is ordered — i.e. has an order_by() clause or a default ordering on the model. False otherwise.
db
The database that will be used if this query is executed now.
Note The query parameter to QuerySet exists so that specialized query subclasses can reconstruct internal query state. The value of the parameter is an opaque representation of that query state and is not part of a public API. | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.