djangodocs.org

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

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.

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

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):

4.2 5.0 5.1 5.2 6.0

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 …

4.2 5.0 5.1 5.2 6.0

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 …

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

Creating objects

Topic guide Making queries

To represent database-table data in Python objects, Django uses an intuitive system: A model class represents a database table, and an instance of that class represents a particular record in the database table.

4.2 5.0 5.1 5.2 6.0

Forward

Topic guide Making queries Related objectsOne-to-many relationships

Subsequent accesses to the foreign key on the same object instance are cached. Example: Note that the select_related() QuerySet method recursively prepopulates the cache of all one-to-many relationships ahead of time. Example:

4.2 5.0 5.1 5.2 6.0

Topic guide Making queries Related objectsMany-to-many relationships

You would expect it to return the entry e. However, the filter condition, which traverses the many-to-many relationship between Entry and Author, yields an empty QuerySet.

6.0

Example

Topic guide Pagination

… you methods for accessing the items for each page: NOTE: Note that you can give Paginator a list/tuple, a Django QuerySet, > or any other object with a count() or __len__() method. When > determining the number of objects contained …

4.2 5.0 5.1 5.2 6.0

H

Index

| | | | --- | --- | | - handle() (BaseCommand method) - handle_app_config() (AppCommand method) - handle_label() (LabelCommand method) - handle_no_permission() (AccessMixin method) - handle_raw_input() (FileUploadHandler method) - handler400 (in module django.conf.urls) - handler403 (in module django.conf.urls) - …

M

Index

| | | | --- | --- | | - m (LineString attribute) - (Point attribute) - mail_admins() (in module django.core.mail) - mail_managers() (in module django.core.mail) - make_aware() (in module django.utils.timezone) - make_list - template filter - make_naive() (in module …

A lookup example

How-to How to write custom lookups

You will need to ensure that this registration happens before you try to create any querysets using it. You could place the implementation in a models.py file, or register the lookup in the ready() method of an AppConfig.

dev

A simple example

Reference The syndication feed framework

This simple example, taken from a hypothetical police beat news site describes a feed of the latest five news items: To connect a URL to this feed, put an instance of the Feed object in your URLconf.

dev