djangodocs.org

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

Retrieving objects

Topic guide Making queries

To retrieve objects from your database, construct a QuerySet via a Manager on your model class. A QuerySet represents a collection of objects from your database. It can have zero, one or many filters.

4.2 5.0 5.1 5.2 6.0

Topic guide Making queries

Sometimes you want to set a field to a particular value for all the objects in a QuerySet. You can do this with the update() method. For example: You can only set non-relation fields and ForeignKey fields using this method.

4.2 5.0 5.1 5.2 6.0

ModelAdmin options

Reference The Django admin site ModelAdmin objects

ModelAdmin.search_help_text : Set search_help_text to specify a descriptive text for the search box which will be displayed below it. ModelAdmin.show_full_result_count : Set show_full_result_count to control whether the full count of objects should be displayed on a filtered admin page (e.g.

4.2 5.0 5.1 5.2 6.0

How-to

Django offers a wide variety of built-in lookups for filtering (for example, exact and icontains). This documentation explains how to write custom lookups and how to alter the working of existing lookups.

dev

How-to

Django offers a wide variety of built-in lookups for filtering (for example, exact and icontains). This documentation explains how to write custom lookups and how to alter the working of existing lookups.

4.2 5.0 5.1 5.2 6.0

Arguments

Reference Model field reference Relationship fieldsManyToManyField

ForeignKey.related_name : The name to use for the relation from the related object back to this one. It’s also the default value for related_query_name (the name to use for the reverse filter name from the target model).

4.2 5.0 5.1

A

Index

… | | --- | --- | | - A (class in django.contrib.gis.measure) - aadd() (RelatedManager method) - aaggregate() (in module django.db.models.query.QuerySet) - aauthenticate() (in module django.contrib.auth) - (ModelBackend method) - (RemoteUserBackend method) - Abs (class in django.db.models.functions) - ABSOLUTE_URL_OVERRIDES - …

E

Index

| | | | --- | --- | | - each_context() (AdminSite method) - earliest() (in module django.db.models.query.QuerySet) - editable (Field attribute) - ELLIPSIS (Paginator attribute) - ellipsoid (SpatialReference attribute) - email (models.User attribute) - EMAIL_BACKEND - setting - EMAIL_FIELD …

I

Index

… - import_wkt() (SpatialReference method) - import_xml() (SpatialReference method) - ImproperlyConfigured - in - field lookup type - in_bulk() (in module django.db.models.query.QuerySet) - include - template tag - include (ExclusionConstraint attribute) - (Index attribute) - (UniqueConstraint attribute) - include() (in module …

2029

Internals Django Deprecation Timeline

Calling QuerySet.aiterator() after prefetch_related() without providing a chunk_size will raise ValueError. The Extract and Trunc database functions will capture the current timezone in migrations when the tzinfo argument is omitted and USE_TZ is True.

dev

ListView

Reference Generic display views

classdjango.views.generic.list.ListView : A page representing a list of objects. classdjango.views.generic.list.BaseListView : A base view for displaying a list of objects.

dev

DateMixin

Reference Date-based mixins

classDateMixin[source] : A mixin class providing common behavior for all date-based views.

dev

SingleObjectMixin

Reference Single object mixins

classdjango.views.generic.detail.SingleObjectMixin : Provides a mechanism for looking up an object associated with the current HTTP request.

dev

Reference Admin actions

Actions may limit their availability to users with specific permissions by wrapping the action function with the action() decorator and passing the permissions argument: The make_published() action will only be available to users that pass the ModelAdmin.has_change_permission() check when it …

dev

Using a SimpleListFilter

Reference ModelAdmin List Filters

… own list filter by subclassing django.contrib.admin.SimpleListFilter. You need to provide the title and parameter_name attributes, and override the lookups and queryset methods, e.g.: NOTE: As a convenience, the HttpRequest object is passed to the lookups > and queryset methods, for …

dev

GeometryDistance

Reference Geographic Database Functions

classGeometryDistance(expr1,expr2,**extra)[source] Availability: PostGIS Accepts two geographic fields or expressions and returns the distance between them. When used in an order_by() clause, it provides index-assisted nearest-neighbor result sets.

dev

Shortcuts

Reference The sitemap framework

The sitemap framework provides a convenience class for a common case: classGenericSitemap(info_dict,priority=None,changefreq=None,protocol=None)[source] : The django.contrib.sitemaps.GenericSitemap class allows you to create a sitemap by passing it a dictionary which has to contain at least a queryset entry.

dev