db.models.Model.validate_unique()

Model.validate_unique(exclude=None) [source] This method is similar to clean_fields(), but validates all uniqueness constraints on your model instead of individual field values. The optional exclude argument allows you to provide a list of field names to exclude from validation. It will raise a ValidationError if any fields fail validation. Note that if you provide an exclude argument to validate_unique(), any unique_together constraint involving one of the fields you provided will not be ch

db.models.Model._base_manager

Model._base_manager

db.models.Model.refresh_from_db()

Model.refresh_from_db(using=None, fields=None) [source] If you need to reload a model’s values from the database, you can use the refresh_from_db() method. When this method is called without arguments the following is done: All non-deferred fields of the model are updated to the values currently present in the database. The previously loaded related instances for which the relation’s value is no longer valid are removed from the reloaded instance. For example, if you have a foreign key from

db.models.Model.save()

Model.save(force_insert=False, force_update=False, using=DEFAULT_DB_ALIAS, update_fields=None) [source] If you want customized saving behavior, you can override this save() method. See Overriding predefined model methods for more details. The model save process also has some subtleties; see the sections below.

db.models.Model.pk

Model.pk Regardless of whether you define a primary key field yourself, or let Django supply one for you, each model will have a property called pk. It behaves like a normal attribute on the model, but is actually an alias for whichever attribute is the primary key field for the model. You can read and set this value, just as you would for any other attribute, and it will update the correct field in the model.

db.models.Model.get_next_by_FOO()

Model.get_next_by_FOO(**kwargs)

db.models.Model.get_previous_by_FOO()

Model.get_previous_by_FOO(**kwargs) For every DateField and DateTimeField that does not have null=True, the object will have get_next_by_FOO() and get_previous_by_FOO() methods, where FOO is the name of the field. This returns the next and previous object with respect to the date field, raising a DoesNotExist exception when appropriate. Both of these methods will perform their queries using the default manager for the model. If you need to emulate filtering used by a custom manager, or want

db.models.Model.get_FOO_display()

Model.get_FOO_display() For every field that has choices set, the object will have a get_FOO_display() method, where FOO is the name of the field. This method returns the “human-readable” value of the field. For example: from django.db import models class Person(models.Model): SHIRT_SIZES = ( ('S', 'Small'), ('M', 'Medium'), ('L', 'Large'), ) name = models.CharField(max_length=60) shirt_size = models.CharField(max_length=2, choices=SHIRT_SIZES) >&

db.models.Model.objects

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 peo

db.models.Model.get_deferred_fields()

Model.get_deferred_fields() [source] A helper method that returns a set containing the attribute names of all those fields that are currently deferred for this model.