djangodocs.org

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

A full example

Topic guide Creating forms from models

Consider this set of models: With these models, the ModelForm subclasses above would be roughly equivalent to this (the only difference being the save() method, which we’ll discuss in a moment.):

dev

Usage

Topic guide Templates

Here’s an example of the search algorithm.

dev

TransactionTestCase

Topic guide Testing tools

classTransactionTestCase[source] TransactionTestCase inherits from SimpleTestCase to add some database-specific features: Resetting the database to a known state at the end of each test to ease testing and using the ORM. Database fixtures. Test skipping based on database backend features.

dev

Membership

Internals Organization of the Django Project Steering council

The steering council selects Mergers as necessary to maintain their number at a minimum of three, in order to spread the workload and avoid over-burdening or burning out any individual Merger.

4.2 5.0 5.1 5.2 6.0

OSGeo4W

Reference GeoDjango Installation Platform-specific instructionsWindows

The OSGeo4W installer helps to install the PROJ, GDAL, and GEOS libraries required by GeoDjango. First, download the OSGeo4W installer, and run it. Select Express Web-GIS Install and click next. In the ‘Select Packages’ list, ensure that GDAL is selected.

4.2 5.0 5.1 5.2 6.0

Storage backends

Reference The messages framework Configuring the message engine

The messages framework can use different backends to store temporary messages. Django provides three built-in storage classes in django.contrib.messages: classstorage.session.SessionStorage : This class stores all messages inside of the request’s session. Therefore it requires Django’s contrib.sessions application.

4.2 5.0 5.1 5.2 6.0

Custom colors

Reference django-admin and manage.py Extra nicetiesSyntax coloring

The colors used for syntax highlighting can be customized. Django ships with three color palettes: dark, suited to terminals that show white text on a black background. This is the default palette.

4.2 5.0 5.1 5.2 6.0

Reference Form fields

Two fields are available for representing relationships between models: ModelChoiceField and ModelMultipleChoiceField. Both of these fields require a single queryset parameter that is used to create the choices for the field.

4.2 5.0 5.1 5.2 6.0

Reference Form fields Fields which handle relationships

By default, ModelChoiceField and ModelMultipleChoiceField use ModelChoiceIterator to generate their field choices. When iterated, ModelChoiceIterator yields 2-tuple choices containing ModelChoiceIteratorValue instances as the first value element in each choice.

4.2 5.0 5.1 5.2 6.0

Reference Widgets Built-in widgets

These widgets make use of the HTML elements <select>, <input type="checkbox">, and <input type="radio">. Widgets that render multiple choices have an option_template_name attribute that specifies the template used to render each choice.

4.2 5.0 5.1 5.2 6.0

Exists() subqueries

Reference Query Expressions Built-in ExpressionsSubquery() expressions

classExists(queryset)[source] Exists is a Subquery subclass that uses an SQL EXISTS statement. In many cases it will perform better than a subquery since the database is able to stop evaluation of the subquery when a first matching row is found.

4.2 5.0 5.1 5.2 6.0

exclude()

Reference QuerySet API reference QuerySet APIMethods that return new QuerySets

exclude(*args,**kwargs) Returns a new QuerySet containing objects that do not match the given lookup parameters. The lookup parameters (**kwargs) should be in the format described in Field lookups below.

4.2 5.0 5.1 5.2 6.0

union()

Reference QuerySet API reference QuerySet APIMethods that return new QuerySets

union(*other_qs,all=False) Uses SQL’s UNION operator to combine the results of two or more QuerySets. For example: The UNION operator selects only distinct values by default. To allow duplicate values, use the all=True argument.

4.2 5.0 5.1 5.2 6.0

latest()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

latest(*fields) alatest(*fields) Asynchronous version: alatest() Returns the latest object in the table based on the given field(s).

4.2 5.0 5.1 5.2 6.0