class documentation

class Model:

Known subclasses: django.contrib.admin.models.LogEntry, django.contrib.auth.models.Group, django.contrib.auth.models.Permission, django.contrib.auth.models.PermissionsMixin, django.contrib.contenttypes.models.ContentType, django.contrib.flatpages.models.FlatPage, django.contrib.redirects.models.Redirect, django.contrib.sessions.base_session.AbstractBaseSession, django.contrib.sites.models.Site, django.contrib.auth.base_user.AbstractBaseUser, django.contrib.gis.db.backends.oracle.models.OracleGeometryColumns, django.contrib.gis.db.backends.oracle.models.OracleSpatialRefSys, django.contrib.gis.db.backends.postgis.models.PostGISGeometryColumns, django.contrib.gis.db.backends.postgis.models.PostGISSpatialRefSys, django.contrib.gis.db.backends.spatialite.models.SpatialiteGeometryColumns, django.contrib.gis.db.backends.spatialite.models.SpatialiteSpatialRefSys

View In Hierarchy

Undocumented

Class Method check Undocumented
Class Method from​_db Undocumented
Class Method ​_check​_column​_name​_clashes Undocumented
Class Method ​_check​_constraints Undocumented
Class Method ​_check​_default​_pk Undocumented
Class Method ​_check​_field​_name​_clashes Forbid field shadowing in multi-table inheritance.
Class Method ​_check​_fields Perform all field checks.
Class Method ​_check​_id​_field Check if id field is a primary key.
Class Method ​_check​_index​_together Check the value of "index_together" option.
Class Method ​_check​_indexes Check fields, names, and conditions of indexes.
Class Method ​_check​_local​_fields Undocumented
Class Method ​_check​_long​_column​_names Check that any auto-generated column names are shorter than the limits for each database in which the model will be created.
Class Method ​_check​_m2m​_through​_same​_relationship Check if no relationship model is used by more than one m2m field.
Class Method ​_check​_managers Perform all manager checks.
Class Method ​_check​_model Undocumented
Class Method ​_check​_model​_name​_db​_lookup​_clashes Undocumented
Class Method ​_check​_ordering Check "ordering" option -- is it a list of strings and do all fields exist?
Class Method ​_check​_property​_name​_related​_field​_accessor​_clashes Undocumented
Class Method ​_check​_single​_primary​_key Undocumented
Class Method ​_check​_swappable Check if the swapped model exists.
Class Method ​_check​_unique​_together Check the value of "unique_together" option.
Class Method ​_get​_expr​_references Undocumented
Method __eq__ Undocumented
Method __getstate__ Hook to allow choosing the attributes to pickle.
Method __hash__ Undocumented
Method __init__ Undocumented
Method __reduce__ Undocumented
Method __repr__ Undocumented
Method __setstate__ Undocumented
Method __str__ Undocumented
Method ​_do​_insert Do an INSERT. If returning_fields is defined then this method should return the newly created data for the model.
Method ​_do​_update Try to update the model. Return True if the model was updated (if an update query was done and a matching row was found in the DB).
Method _get_​FIELD_display Undocumented
Method _get_next_or_previous_by_​FIELD Undocumented
Method ​_get​_next​_or​_previous​_in​_order Undocumented
Method ​_get​_pk​_val Undocumented
Method ​_get​_unique​_checks No summary
Method ​_perform​_date​_checks Undocumented
Method ​_perform​_unique​_checks Undocumented
Method ​_prepare​_related​_fields​_for​_save Undocumented
Method ​_save​_parents Save all the parents of cls using values from self.
Method ​_save​_table Do the heavy-lifting involved in saving. Update or insert the data for a single table.
Method ​_set​_pk​_val Undocumented
Method clean No summary
Method clean​_fields Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.
Method date​_error​_message Undocumented
Method delete Undocumented
Method full​_clean Call clean_fields(), clean(), and validate_unique() on the model. Raise a ValidationError for any errors that occur.
Method get​_deferred​_fields Return a set containing names of deferred fields for this instance.
Method prepare​_database​_save Undocumented
Method refresh​_from​_db Reload field values from the database.
Method save Save the current instance. Override this in a subclass if you want to control the saving process.
Method save​_base Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too. This includes some sanity checks and signal sending.
Method serializable​_value No summary
Method unique​_error​_message Undocumented
Method validate​_unique Check unique constraints on the model and raise ValidationError if any failed.
Class Variable pk Undocumented
Instance Variable ​_order Undocumented
Instance Variable ​_prefetched​_objects​_cache Undocumented
Instance Variable ​_state Undocumented
@classmethod
def check(cls, **kwargs):

Undocumented

@classmethod
def from_db(cls, db, field_names, values):

Undocumented

@classmethod
def _check_column_name_clashes(cls):

Undocumented

@classmethod
def _check_constraints(cls, databases):

Undocumented

@classmethod
def _check_default_pk(cls):

Undocumented

@classmethod
def _check_field_name_clashes(cls):
Forbid field shadowing in multi-table inheritance.
@classmethod
def _check_fields(cls, **kwargs):
Perform all field checks.
@classmethod
def _check_id_field(cls):
Check if id field is a primary key.
@classmethod
def _check_index_together(cls):
Check the value of "index_together" option.
@classmethod
def _check_indexes(cls, databases):
Check fields, names, and conditions of indexes.
@classmethod
def _check_local_fields(cls, fields, option):

Undocumented

@classmethod
def _check_long_column_names(cls, databases):
Check that any auto-generated column names are shorter than the limits for each database in which the model will be created.
@classmethod
def _check_m2m_through_same_relationship(cls):
Check if no relationship model is used by more than one m2m field.
@classmethod
def _check_managers(cls, **kwargs):
Perform all manager checks.
@classmethod
def _check_model(cls):

Undocumented

@classmethod
def _check_model_name_db_lookup_clashes(cls):

Undocumented

@classmethod
def _check_ordering(cls):
Check "ordering" option -- is it a list of strings and do all fields exist?
@classmethod
def _check_property_name_related_field_accessor_clashes(cls):

Undocumented

@classmethod
def _check_single_primary_key(cls):

Undocumented

@classmethod
def _check_swappable(cls):
Check if the swapped model exists.
@classmethod
def _check_unique_together(cls):
Check the value of "unique_together" option.
@classmethod
def _get_expr_references(cls, expr):

Undocumented

def __eq__(self, other):

Undocumented

def __getstate__(self):
Hook to allow choosing the attributes to pickle.
def __hash__(self):

Undocumented

def __init__(self, *args, **kwargs):

Undocumented

def __reduce__(self):

Undocumented

def __repr__(self):

Undocumented

def __setstate__(self, state):

Undocumented

def _do_insert(self, manager, using, fields, returning_fields, raw):
Do an INSERT. If returning_fields is defined then this method should return the newly created data for the model.
def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_update):
Try to update the model. Return True if the model was updated (if an update query was done and a matching row was found in the DB).
def _get_FIELD_display(self, field):

Undocumented

def _get_next_or_previous_by_FIELD(self, field, is_next, **kwargs):

Undocumented

def _get_next_or_previous_in_order(self, is_next):

Undocumented

def _get_pk_val(self, meta=None):

Undocumented

def _get_unique_checks(self, exclude=None):
Return a list of checks to perform. Since validate_unique() could be called from a ModelForm, some fields may have been excluded; we can't perform a unique check on a model that is missing fields involved in that check. Fields that did not validate should also be excluded, but they need to be passed in via the exclude argument.
def _perform_date_checks(self, date_checks):

Undocumented

def _perform_unique_checks(self, unique_checks):

Undocumented

def _prepare_related_fields_for_save(self, operation_name):

Undocumented

def _save_parents(self, cls, using, update_fields):
Save all the parents of cls using values from self.
def _save_table(self, raw=False, cls=None, force_insert=False, force_update=False, using=None, update_fields=None):
Do the heavy-lifting involved in saving. Update or insert the data for a single table.
def _set_pk_val(self, value):

Undocumented

def clean(self):
Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
def clean_fields(self, exclude=None):
Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.
def date_error_message(self, lookup_type, field_name, unique_for):

Undocumented

def delete(self, using=None, keep_parents=False):

Undocumented

def full_clean(self, exclude=None, validate_unique=True):
Call clean_fields(), clean(), and validate_unique() on the model. Raise a ValidationError for any errors that occur.
def get_deferred_fields(self):
Return a set containing names of deferred fields for this instance.
def prepare_database_save(self, field):

Undocumented

def refresh_from_db(self, using=None, fields=None):

Reload field values from the database.

By default, the reloading happens from the database this instance was loaded from, or by the read router if this instance wasn't loaded from any database. The using parameter will override the default.

Fields can be used to specify which fields to reload. The fields should be an iterable of field attnames. If fields is None, then all non-deferred fields are reloaded.

When accessing deferred fields of an instance, the deferred loading of the field will call this method.

def save(self, force_insert=False, force_update=False, using=None, update_fields=None):

Save the current instance. Override this in a subclass if you want to control the saving process.

The 'force_insert' and 'force_update' parameters can be used to insist that the "save" must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

def save_base(self, raw=False, force_insert=False, force_update=False, using=None, update_fields=None):

Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too. This includes some sanity checks and signal sending.

The 'raw' argument is telling save_base not to save any parent models and not to do any changes to the values before save. This is used by fixture loading.

def serializable_value(self, field_name):

Return the value of the field name for this instance. If the field is a foreign key, return the id value instead of the object. If there's no Field object with this name on the model, return the model attribute's value.

Used to serialize a field's value (in the serializer, or form output, for example). Normally, you would just access the attribute directly and not use this method.

def unique_error_message(self, model_class, unique_check):

Undocumented

def validate_unique(self, exclude=None):
Check unique constraints on the model and raise ValidationError if any failed.
pk =

Undocumented

_order =

Undocumented

_prefetched_objects_cache: dict =

Undocumented

_state =

Undocumented