djangodocs.org

1413 sections across all versions Narrow to Django 6.0 (current) →

Model instance reference

Reference

This document describes the details of the Model API. It builds on the material presented in the model and database query guides, so you’ll probably want to read and understand those documents before reading this one.

4.2 5.0 5.1 5.2 6.0

get_latest_by

Reference Model Meta options Available Meta options

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.

4.2 5.0 5.1 5.2 6.0

Reference

classRelatedManager : A “related manager” is a manager used in a one-to-many or many-to-many related context. This happens in two cases:

4.2 5.0 5.1 5.2 6.0

Attributes

Reference Paginator Page class

Paginator.ELLIPSIS : A translatable string used as a substitute for elided page numbers in the page range returned by get_elided_page_range(). Default is '…'. Paginator.count[source] : The total number of objects, across all pages. Paginator.num_pages[source] : The total number of pages.

4.2 5.0 5.1 5.2 6.0

post_init

Reference Signals Model signals

WARNING: For performance reasons, you shouldn’t perform queries in receivers of > pre_init or post_init signals because they would be executed for > each instance returned during queryset iteration.

4.2 5.0 5.1 5.2 6.0

in operator

Reference Built-in template tags and filters Built-in tag referenceifBoolean operators

Contained within. This operator is supported by many Python containers to test whether the given value is in the container. The following are some examples of how x in y will be interpreted:

4.2 5.0 5.1 5.2 6.0

Topic guide Built-in class-based generic views Generic views of objects

… specify the objects that the view will operate upon – you can also specify the list of objects using the queryset argument: Specifying model = Publisher is shorthand for saying queryset = Publisher.objects.all(). However, by using queryset to define a …

4.2 5.0 5.1 5.2 6.0

Model forms

Topic guide Form handling with class-based views

If a queryset is given, the model for that queryset will be used. Model form views provide a form_valid() implementation that saves the model automatically. You can override this if you have any special requirements; see below for examples.

4.2 5.0 5.1 5.2 6.0

Topic guide Class-based views Subclassing generic views

Suppose somebody wants to access our book library over HTTP using the views as an API. The API client would connect every now and then and download book data for the books published since last visit.

4.2 5.0 5.1 5.2 6.0