djangodocs.org

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

Glossary

queryset : An object representing some set of rows to be fetched from the database. slug : A short label for something, containing only letters, numbers, underscores or hyphens. They’re generally used in URLs.

Custom database types

How-to How to create custom model fields Writing a field subclassUseful methods

The methods are also called when constructing a WHERE clause that includes the model field – that is, when you retrieve data using QuerySet methods like get(), filter(), and exclude() and have the model field as an argument.

1.7

Internals Django Deprecation Timeline

See the Django 1.5 release notes for more details on these changes. The module django.utils.simplejson will be removed. The standard library provides json which should be used instead. The function django.utils.itercompat.product will be removed.

dev

Internals The Django source code repository Tags

queryset-refactor: A refactoring of the internals of Django’s object-relational mapper. This became part of Django as of the 1.0 release. unicode: A refactoring of Django’s internals to consistently use Unicode-based strings in most places within Django and Django applications.

Internals Django’s security policies Reporting security issuesReporting guidelines

Reports based on a failure to sanitize user input are not valid security vulnerabilities. It is the developer’s responsibility to properly handle user input. This principle is explained in our security documentation.

5.1 5.2 6.0 dev

Troubleshooting

Reference Applications Initialization process

For example, a common mistake is making a database query to populate form field choices: In the example above, the query from Country.objects.all() is executed during module import, because the QuerySet is iterated over.

5.0 5.1 5.2 6.0 dev

ArchiveIndexView

Reference Class-based generic views - flattened index Date-based views

… accessor): allow_empty [get_allow_empty()] allow_future [get_allow_future()] content_type context_object_name [get_context_object_name()] date_field [get_date_field()] extra_context http_method_names model ordering [get_ordering()] paginate_by [get_paginate_by()] paginate_orphans [get_paginate_orphans()] paginator_class queryset [get_queryset()] response_class [render_to_response()] template_engine template_name [get_template_names()] template_name_suffix Methods as_view() dispatch() get() get_context_data() get_date_list() get_dated_items() get_dated_queryset() get_paginator() head() http_method_not_allowed() paginate_queryset() …

DateDetailView

Reference Class-based generic views - flattened index Date-based views

… (with optional accessor): allow_future [get_allow_future()] content_type context_object_name [get_context_object_name()] date_field [get_date_field()] day [get_day()] day_format [get_day_format()] extra_context http_method_names model month [get_month()] month_format [get_month_format()] pk_url_kwarg query_pk_and_slug queryset [get_queryset()] response_class [render_to_response()] slug_field [get_slug_field()] slug_url_kwarg template_engine template_name [get_template_names()] template_name_field template_name_suffix year [get_year()] year_format [get_year_format()] Methods

WeekArchiveView

Reference Generic date views

classWeekArchiveView[source] : A weekly archive page showing all objects in a given week. Objects with a date in the future are not displayed unless you set allow_future to True.

DayArchiveView

Reference Generic date views

classDayArchiveView[source] : A day archive page showing all objects in a given day. Days in the future throw a 404 error, regardless of whether any objects exist for future days, unless you set allow_future to True.

BaseDateListView

Reference Date-based mixins

classBaseDateListView[source] : A base class that provides common behavior for all date-based views. There won’t normally be a reason to instantiate BaseDateListView; instantiate one of the subclasses instead.

Manager methods

Reference django.contrib.auth User model

classmodels.UserManager : The User model has a custom manager that has the following helper methods (in addition to the methods provided by BaseUserManager):

Distance

Reference Geographic Database Functions Measurements

… more resource-intensive). In the following example, the distance from the city of Hobart to every other PointField in the AustraliaCity queryset is calculated: NOTE: Because the distance attribute is a > Distance object, you can easily > express the value …

GeoDjango

Reference

… with Raster Fields Spatial Lookups Distance Queries Compatibility Tables GeoDjango Forms API Field arguments Form field classes Form widgets GIS QuerySet API Reference Spatial Lookups Distance Lookups Geographic Database Functions Measurements Relationships Operations Editors Input format Output format Miscellaneous Measurement …

Reference Databases PostgreSQL notesServer-side cursors

Another option is to wrap each QuerySet using server-side cursors in an atomic() block, because it disables autocommit for the duration of the transaction. This way, the server-side cursor will only live for the duration of the transaction.

Extract

Reference Database Functions Date functions

classExtract(expression,lookup_name=None,tzinfo=None,**extra)[source] Extracts a component of a date as a number. Takes an expression representing a DateField, DateTimeField, TimeField, or DurationField and a lookup_name, and returns the part of the date referenced by lookup_name as an IntegerField.

F() expressions

Reference Query Expressions Built-in Expressions

As well as being used in operations on single instances as above, F() can be used with update() to perform bulk updates on a QuerySet.

dev

ordering

Reference Model Meta options Available Meta options

Options.ordering : The default ordering for the object, for use when obtaining lists of objects: NOTE: In GROUP BY queries (for example, > those using values() and annotate()), the > default ordering is not applied.

5.2 6.0 dev

Topic guide

Article.objects.filter(reporter__first_name="John") <QuerySet [<Article: John's second story>, <Article: This is a test>]> Query twice over the related field.