db.models.Model.get_absolute_url()

Model.get_absolute_url() Define a get_absolute_url() method to tell Django how to calculate the canonical URL for an object. To callers, this method should appear to return a string that can be used to refer to the object over HTTP. For example: def get_absolute_url(self): return "/people/%i/" % self.id While this code is correct and simple, it may not be the most portable way to to write this kind of method. The reverse() function is usually the best approach. For example: def get_abso

db.models.Model.full_clean()

Model.full_clean(exclude=None, validate_unique=True) [source] This method calls Model.clean_fields(), Model.clean(), and Model.validate_unique() (if validate_unique is True), in that order and raises a ValidationError that has a message_dict attribute containing errors from all three stages. The optional exclude argument can be used to provide a list of field names that can be excluded from validation and cleaning. ModelForm uses this argument to exclude fields that aren’t present on your fo

db.models.Model.delete()

Model.delete(using=DEFAULT_DB_ALIAS, keep_parents=False) [source] Issues an SQL DELETE for the object. This only deletes the object in the database; the Python instance will still exist and will still have data in its fields. This method returns the number of objects deleted and a dictionary with the number of deletions per object type. For more details, including how to delete objects in bulk, see Deleting objects. If you want customized deletion behavior, you can override the delete() meth

db.models.Model.clean_fields()

Model.clean_fields(exclude=None) [source] This method will validate all fields on your model. The optional exclude argument lets you provide a list of field names to exclude from validation. It will raise a ValidationError if any fields fail validation. The second step full_clean() performs is to call Model.clean(). This method should be overridden to perform custom validation on your model.

db.models.Model.clean()

Model.clean() [source] This method should be used to provide custom model validation, and to modify attributes on your model if desired. For instance, you could use it to automatically provide a value for a field, or to do validation that requires access to more than a single field: import datetime from django.core.exceptions import ValidationError from django.db import models from django.utils.translation import ugettext_lazy as _ class Article(models.Model): ... def clean(self):

db.models.Model

class Model(**kwargs) [source] The keyword arguments are simply the names of the fields you’ve defined on your model. Note that instantiating a model in no way touches your database; for that, you need to save(). Note You may be tempted to customize the model by overriding the __init__ method. If you do so, however, take care not to change the calling signature as any change may prevent the model instance from being saved. Rather than overriding __init__, try using one of these approaches:

db.models.Min

class Min(expression, output_field=None, **extra) [source] Returns the minimum value of the given expression. Default alias: <field>__min Return type: same as input field, or output_field if supplied

db.models.Max

class Max(expression, output_field=None, **extra) [source] Returns the maximum value of the given expression. Default alias: <field>__max Return type: same as input field, or output_field if supplied

db.models.ManyToManyField.through_fields

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,

db.models.ManyToManyField.through

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. If you don’t specify an explicit through model, there is still an implicit through model class