djangodocs.org

674 sections in Django 4.2 Search all versions →

TodayArchiveView

Reference Generic date views

classTodayArchiveView : A day archive page showing all objects for today. This is exactly the same as django.views.generic.dates.DayArchiveView, except today’s date is used instead of the year/month/day arguments.

DetailView

Reference Generic display views

classdjango.views.generic.detail.DetailView : While this view is executing, self.object will contain the object that the view is operating upon. classdjango.views.generic.detail.BaseDetailView : A base view for displaying a single object.

ModelFormMixin

Reference Editing mixins

classdjango.views.generic.edit.ModelFormMixin : A form mixin that works on ModelForms, rather than a standalone form.

MultipleObjectMixin

Reference Multiple object mixins

`context_object_name` : Designates the name of the variable to use in the context. `get_queryset()` : Get the list of items for this view. This must be an iterable and may be a queryset (in which queryset-specific behavior will be enabled).

SingleObjectMixin

Reference Single object mixins

If [`context_object_name`](#django.views.generic.detail.SingleObjectMixin.context_object_name) is not set, the context name will be constructed from the `model_name` of the model that the queryset is composed from. For example, the model `Article` would have context object named `'article'`.

Admin actions

Reference

For example, here’s the user module from Django’s built-in django.contrib.auth app: WARNING: The “delete selected objects” action uses QuerySet.delete() for efficiency reasons, which > has an important caveat: your model’s delete() method will not be > called.

Writing action functions

Reference Admin actions Writing actions

Action functions are regular functions that take three arguments: The current ModelAdmin An HttpRequest representing the current request, A QuerySet containing the set of objects selected by the user.

Reference Admin actions Advanced action techniques

By default, after an action is performed the user is redirected back to the original change list page. However, some actions, especially more complex ones, will need to return intermediate pages.

ModelAdmin options

Reference The Django admin site ModelAdmin objects

ModelAdmin.ordering : Set ordering to specify how lists of objects should be ordered in the Django admin views. This should be a list or tuple in the same format as a model’s ordering parameter.

ModelAdmin methods

Reference The Django admin site ModelAdmin objects

ModelAdmin.formfield_for_foreignkey(db_field,request,**kwargs) : The formfield_for_foreignkey method on a ModelAdmin allows you to override the default formfield for a foreign keys field.

InlineModelAdmin options

Reference The Django admin site InlineModelAdmin objects

The shared features are: form fieldsets fields formfield_overrides exclude filter_horizontal filter_vertical ordering prepopulated_fields get_fieldsets() get_queryset() radio_fields readonly_fields raw_id_fields formfield_for_choice_field() formfield_for_foreignkey() formfield_for_manytomany() has_module_permission() The InlineModelAdmin class adds or customizes: InlineModelAdmin.model : The model which the inline is using. This is required.

Reference django.contrib.auth Authentication backends

classAllowAllUsersModelBackend : Same as ModelBackend except that it doesn’t reject inactive users because user_can_authenticate() always returns True. classRemoteUserBackend : Use this backend to take advantage of external-to-Django-handled authentication. It authenticates using usernames passed in request.META['REMOTE_USER'].

Reference The contenttypes framework

Each ContentType instance has methods that allow you to get from a ContentType instance to the model it represents, or to retrieve objects from that model: ContentType.get_object_for_this_type(**kwargs) : Takes a set of valid lookup arguments for the model the ContentType …

Spatial Lookups

Reference GeoDjango Tutorial Spatial Queries

[4] Import the WorldBorder model, and perform a contains lookup using the pnt_wkt as the parameter: Here, you retrieved a QuerySet with only one model: the border of the United States (exactly what you would expect).

overlap

Reference PostgreSQL specific model fields Range FieldsQuerying Range FieldsContainment functions

Returns objects where the data shares any results with the values passed. Uses the SQL operator &&. For example: Changed in Django 4.2: Support for QuerySet.values() and values_list() as a right-hand > side was added.

An example

Reference The sitemap framework

items() is a method that returns a sequence or QuerySet of objects. The objects returned will get passed to any callable methods corresponding to a sitemap property (location, lastmod, changefreq, and priority). lastmod should return a datetime.